我以编程方式创建一个按钮............
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:]来执行此操作。
-[UIButton setTitleColor:forState:]
例子:
Objective-C
[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
斯威夫特 2
buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)
斯威夫特 3
buttonName.setTitleColor(UIColor.white, for: .normal)