如何更改 titleLabel 字体颜色,Xcode

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11258713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:27:27  来源:igfitidea点击:

How to change the titleLabel font color, Xcode

xcodeuibuttonlabeluicolor

提问by Mrwolfy

This code seems to work well, modifying the properties of my button, except the titleLabel font color is not changing. I can change the font, font size, shadow but not the color. It currently displays as white although I am trying to set it to black. I've tried button1.titleLabel.textColor = [UIColor blackColor]; and [button1.titleLabel setTextColor:[UIColor blackColor]]; seems to recognize the property but still remains white.

这段代码似乎运行良好,修改了我的按钮的属性,除了 titleLabel 字体颜色没有改变。我可以更改字体、字体大小、阴影,但不能更改颜色。尽管我试图将其设置为黑色,但它目前显示为白色。我试过 button1.titleLabel.textColor = [UIColor blackColor]; 和 [button1.titleLabel setTextColor:[UIColor blackColor]]; 似乎认出了这个财产,但仍然是白色的。

[button1.titleLabel setTextColor:[UIColor blackColor]];        
[button1.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[button1.titleLabel setShadowColor:[UIColor blackColor]];
[button1.titleLabel setShadowOffset:CGSizeMake(-1, 1)];
[button1 setTitle:@"Do it" forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 0, 250, 40.0);
[myView addSubview:button1];

回答by Mrwolfy

This worked.

这奏效了。

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