【问题标题】:Change in Button text color not reflecting按钮文本颜色的变化未反映
【发布时间】:2023-03-10 06:50:01
【问题描述】:

我遇到了一个奇怪的问题。当按钮突出显示时,我正在更改按钮的文本颜色,但视觉上没有任何变化。

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

我错过了什么吗?

【问题讨论】:

    标签: iphone cocoa-touch ios object uibutton


    【解决方案1】:

    试试:

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

    颜色分量是介于 0.0 和 1.0 之间的浮点数!

    【讨论】:

    • 颜色分量在 0.0 和 1.0 之间浮动,但索引从 0 开始:float/255.0 应该是:[UIColor colorWithRed:150.0/255.0 green:150.0/255.0 blue:150.0/255.0 alpha:1.0]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 2018-08-15
    • 2016-11-13
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多