我有UIButton
,它有预设的文字字体和颜色,我需要在点击点按按钮时立即更改。
我试试:
- (IBAction)tapAction : (id)sender
{
// determine button from tag ..
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateSelected];
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal];
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateApplication];
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateHighlighted];
[crtBtn setNeedsDisplay];
}
任何想法如何解决这个问题?
答案 0 :(得分:2)
试试这段代码:
- (IBAction)tapAction : (id)sender
{
[sender setTitleColor:self.selectedTextColor forState:UIControlStateNormal]
}
答案 1 :(得分:1)
我想,你没有为你设置IBOutlet按钮(使用crtBtn)。
- (IBAction)tapAction : (id)sender
{
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal];
// or
[sender setTitleColor:self.selectedTextColor forState:UIControlStateNormal]
}
答案 2 :(得分:1)
这对我有用:
-(IBAction)tapAction: (UIButton *)sender
{
[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal];
}