小编典典

如何更改 UIButton 标题颜色?

all

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

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

如何更改标题颜色?


阅读 57

收藏
2022-06-29

共1个答案

小编典典

您可以使用它-[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)
2022-06-29