更改UIButton标题不起作用
我在tableview单元格中添加了一个按钮。我的问题是,当我改变它的标题调用方法pressHonkBtn:(id)sender
它不改变它的标题。更改UIButton标题不起作用
如何解决这个问题。
使用你的代码,因为这:
的Objective-C:
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *tempBtn = (UIButton *)sender;
[tempBtn setTitle:@"YOUR_TITLE" forState:UIControlStateNormal];// YOUR_TITLE is your button title
[tempBtn setTitle:@"YOUR_TITLE" forState:UIControlStateHighlighted];
}
斯威夫特:
someUIButton.setTitle("String To Set", forState: UIControlState.Normal)
希望它可以帮助你。
没有必要设置标题的状态突出。 – 2013-05-03 12:17:45
@Divz我认为你不知道这一点。我们也需要为突出显示的状态设置标题。 – 2013-05-03 12:22:58
我认为你应该由你自己来做,我对此充满信心。 – 2013-05-03 12:23:22
由于您正在接收id作为参数,因此您需要将其转换为UIButton。
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *senderBtn = (UIButton *)sender;
[senderBtn setTitle:[NSString stringWithFormat:@"Title"] forState:UIControlStateNormal];
}
感谢您的宝贵评论家,我可以知道投票的理由 – 2013-05-03 12:33:14
请尝试使用这一个.....它会正常工作。
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[btn setTitle:@"title" forState:UIControlStateNormal];
}
试试这个:
-(IBAction)pressHonkBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[btn setTitle:@"title" forState:UIControlStateNormal];
[btn setTitle:@"title" forState:UIControlStateHighlighted];
}
把你的代码在这里 – 2013-05-03 12:13:24
日Thnx所有,我的问题解决了 – 2013-05-04 05:50:20
你的欢迎亩,亲爱的... – 2013-05-04 05:55:08