我以编程方式创建一个按钮..........
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];
如何更改 Headers 颜色?
5 回答
您可以使用
-[UIButton setTitleColor:forState:]
执行此操作 .例:
Objective-C
Swift 2
Swift 3
感谢richardchildan
你创建的
UIButton
添加了ViewController
,以下实例方法改变了UIFont
,tintColor
和TextColor
的UIButton
Objective-C
Swift
Swift3
Solution in Swift 3 :
这将设置按钮的 Headers 颜色 .
如果您使用Swift,这将做同样的事情:
buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)
希望有所帮助!
使用Swift 3,
UIButton
具有setTitleColor(_:for:)方法 .setTitleColor(_:for:)
有以下声明:以下Playground代码显示如何在
UIViewController
中创建UIbutton
并使用setTitleColor(_:for:)
更改其 Headers 颜色:在Playground中选择
Show the Assistant Editor
>Timeline <Name of the page>.xcplaygroundpage
以显示UIViewController
已创建的实例 .