Ios UIButton标题标签在按下时调整大小?

Ios UIButton标题标签在按下时调整大小?,ios,uikit,Ios,Uikit,我试图根据按下的状态给UIButton(它是用大小调整图像创建的)一些文本。我看到的行为是,当我按下按钮时,按钮图像的宽度会改变(变宽)。我想要的是文本在我按下时发生变化,但按钮的宽度保持不变。我已经摆弄了许多UIButton选项,但运气不好。下面是我目前正在做的:(有趣的是,按钮宽度的变化量似乎与按钮框架的宽度相关(更大->更多变化): 我想说你在反对自动布局(我看到了类似的行为,有人在这里回答了我的问题:),但我不确定当你问这个问题时是否存在。 UIImage *normalButton =

我试图根据按下的状态给UIButton(它是用大小调整图像创建的)一些文本。我看到的行为是,当我按下按钮时,按钮图像的宽度会改变(变宽)。我想要的是文本在我按下时发生变化,但按钮的宽度保持不变。我已经摆弄了许多UIButton选项,但运气不好。下面是我目前正在做的:(有趣的是,按钮宽度的变化量似乎与按钮框架的宽度相关(更大->更多变化):


我想说你在反对自动布局(我看到了类似的行为,有人在这里回答了我的问题:),但我不确定当你问这个问题时是否存在。
UIImage *normalButton = [UIImage imageNamed:@"ButtonSlice.png"];
UIImage *pressedButton = [UIImage imageNamed:@"ButtonPressedSlice.png"];
normalButton = [normalButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 2)];
pressedButton = [pressedButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 2)];

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
[myButton setImage:normalButton forState:UIControlStateNormal];
[myButton setImage:pressedButton forState:UIControlStateHighlighted];
[myButton addTarget:self action:@selector(pressed) forControlEvents:UIControlEventTouchUpInside];

myButton.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:18.0];

[myButton setTitleColor:[UIColor colorWithWhite:0.1 alpha:1] forState:UIControlStateNormal];
[myButton setTitle:@"Highlighted" forState:UIControlStateHighlighted];
[myButton setTitle:@"Default" forState:UIControlStateNormal];
myButton.titleLabel.textAlignment = UITextAlignmentCenter;

//No effect?
myButton.adjustsImageWhenHighlighted = NO;

myButton.frame = CGRectMake(ceil(controllerFrame.size.width/2 - 100), 80, 200, 50);