我试图通过以下代码为UIButton设置UIImage,但没有任何反应。我在viewDidLoad中设置这些。它出现的唯一方法是我使用故事板并以这种方式设置图像。
- (void)viewDidLoad
{
...
[self.locateMeButton setFrame:CGRectMake(11, 11, 46, 46)];
[self.locateMeButton setImage:[UIImage imageNamed:@"locateme_disabled.png"] forState:UIControlStateDisabled];
[self.locateMeButton setImage:[UIImage imageNamed:@"locateme_active.png"] forState:UIControlStateHighlighted];
[self.locateMeButton setBackgroundImage:[UIImage imageNamed:@"locateme_normal.png"] forState:UIControlStateNormal];
...
}
答案 0 :(得分:0)
UIButton *aboutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[aboutBtn addTarget:self action:@selector(showAboutPage) forControlEvents:UIControlEventTouchUpInside];
[aboutBtn setTitle:@"About Me" forState:UIControlStateNormal];
[aboutBtn setFrame:CGRectMake(80.0, 120.0, 162.0, 42.0)];
[aboutBtn setBackgroundImage:[UIImage imageNamed:@"locateme_normal.png"] forState:UIControlStateNormal];
[aboutBtn setBackgroundImage:[UIImage imageNamed:@"locateme_disabled.png"] forState:UIControlStateHighlighted];
答案 1 :(得分:0)
我有类似的问题。在我的情况下,我发现我正在重新创建工具栏,因此使用了错误的工具栏对象。 (试图访问错误工具栏上的按钮)。基本上,系统地检查您的方法是否对您期望的所有接收器起作用并且正在传递您期望的参数值似乎是一个好主意。