如何更改UIButton标题颜色? [英] How can I change UIButton title color?
本文介绍了如何更改UIButton标题颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以编程方式创建一个按钮..........
button = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[button addTarget:self action:@selector(aMethod :)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@Show ViewforState:UIControlStateNormal];
button.frame = CGRectMake(80.0,210.0,160.0,40.0);
[查看addSubview:button];
如何更改标题颜色?
解决方案
您可以使用 - [UIButton setTitleColor:forState:]
来执行此操作。
示例:
Objective-C
[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Swift 2
buttonName.setTitleColor(UIColor.blackColor(),forState:。正常)
Swift 3
buttonName.setTitleColor(UIColor.white,for:。 (b)感谢 richardchildan
I create a button programmatically..........
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
how can I change title color?
解决方案 You can use -[UIButton setTitleColor:forState:]
to do this.
Example:
Objective-C
[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Swift 2
buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)
Swift 3
buttonName.setTitleColor(UIColor.white, for: .normal)
Thanks to richardchildan
这篇关于如何更改UIButton标题颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文