ios 按钮文本颜色的变化没有反映

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6078729/
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-08-30 20:02:47  来源:igfitidea点击:

Change in Button text color not reflecting

iphonecocoa-touchiosobjectuibutton

提问by Abhinav

I am facing a weird issue. I am changing the text color of my button when it is highlighted but visually no change at all.

我正面临一个奇怪的问题。当我的按钮突出显示时,我正在更改它的文本颜色,但在视觉上根本没有变化。

[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor colorWithRed:150.0 green:150.0 blue:150.0 alpha:1.0] forState:UIControlStateHighlighted];

Am I missing something?

我错过了什么吗?

回答by Roki

try:

尝试:

[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor colorWithRed:150.0/256.0 green:150.0/256.0 blue:150.0/256.0 alpha:1.0] forState:UIControlStateHighlighted];

Color components are floats between 0.0 and 1.0 !

颜色分量在 0.0 和 1.0 之间浮动!