ios - 如何更改 UIButton 标题颜色?

我以编程方式创建了一个按钮............

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];

如何更改标题颜色?

最佳答案

您可以使用 -[UIButton setTitleColor:forState:] 来执行此操作。

例子:

Objective-C

[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

swift 2

buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)

swift 3

buttonName.setTitleColor(UIColor.white, for: .normal)

感谢 richardchildan

https://stackoverflow.com/questions/2474289/

相关文章:

ios - iOS 7+ 中的 Base64 解码

ios - 等到两个异步 block 被执行后再开始另一个 block

objective-c - 项目构建中的 CocoaPods 错误

objective-c - Objective-C 中的 NULL 与 nil

ios - 从 UIView 到 UIViewController?

ios - 动态改变UILabel的字体大小

iphone - 如何在 Objective-C 中定义和使用 ENUM?

ios - 在没有 UITableViewController 的情况下拉取刷新 UITableVi

ios - 尝试将非属性列表对象设置为 NSUserDefaults

ios - 在 Objective-C 中检查空字符串的正确方法是什么?