【发布时间】:2015-02-08 00:57:52
【问题描述】:
我有一个 UIButton,我已成功为其设置了背景图像。我想在用户点击它时更改背景图像(导航到下一个视图控制器)。不幸的是,点击时背景不会改变。但是,当我点击并按住按钮时,它确实发生了变化,所以我很困惑。代码如下所示:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x_offset, y_offset, width, BUTTON_HEIGHT)];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
UIImage *buttonImage = [[UIImage imageNamed:@"main_button"]
resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
UIImage *pressedbuttonImage = [[UIImage imageNamed:@"main_button_pressed"]
resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:pressedbuttonImage forState:UIControlStateHighlighted];
[button setBackgroundImage:pressedbuttonImage forState:UIControlStateApplication];
[button setBackgroundImage:pressedbuttonImage forState:UIControlStateDisabled];
[button setBackgroundImage:pressedbuttonImage forState:UIControlStateReserved];
[button setBackgroundImage:pressedbuttonImage forState:UIControlStateSelected];
return button;
我知道我在 UIControlStates 上做得过火了,但我想演示一下我已经全部尝试过了:)
【问题讨论】:
标签: ios objective-c uibutton