UIButton wierdness:无法为自定义按钮类型设置标题

时间:2012-03-03 21:44:19

标签: ios cocoa-touch uibutton

我正在尝试为我以编程方式创建的自定义按钮设置标题。按钮的图像和框架显示正常,但标题没有。我真的不能想到这段代码有什么问题,所以任何帮助都是不合理的!

self.helpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.helpButton setFrame:CGRectMake(113.0, 685.5, 73.0, 40.0)];
UIImage *helpImg = [UIImage imageNamed:@"11_HelpCancel_Up.png"];
[self.helpButton setImage:helpImg 
               forState:UIControlStateNormal];
[self.helpButton setTitle:@"Help" forState:UIControlStateNormal];
[self.helpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// [self.helpButton setFont:[UIFont boldSystemFontOfSize:14.0]];
[self.view addSubview:self.helpButton];

谢谢,
的Teja。

2 个答案:

答案 0 :(得分:9)

使用

[self.helpButton setBackgroundImage:helpImg forState:UIControlStateNormal];

- setImage:forState:似乎覆盖了- setTitle:forState:

答案 1 :(得分:0)

当我从系统切换按钮类型时,我的故事板上显示的按钮标题出现问题 - >定制。问题是当我进行更改时文本的颜色变为白色,所以任何人都有类似的问题,请务必检查按钮文本的颜色。

相关问题