我以编程方式创建了一个按钮............
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/