0

我正在尝试通过以下代码为 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];
  ...

 }
4

2 回答 2

0

我有一个类似的问题。事实证明,我正在重新创建工具栏,因此使用了错误的工具栏对象。(试图访问错误工具栏上的按钮)。基本上,系统地检查您的方法是否作用于您期望的所有接收器并传递您期望的参数值似乎是个好主意。

于 2014-05-02T20:30:36.733 回答
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];
于 2013-06-03T04:19:51.653 回答