【问题标题】:Swift custom rgb color not shownSwift 自定义 rgb 颜色未显示
【发布时间】:2021-09-24 21:19:52
【问题描述】:

所以我使用来自https://www.rapidtables.com/convert/color/hex-to-rgb.html 的自定义颜色作为单元格中的按钮标题。但不知何故,有些颜色没有像银色 RGB((192,192,192) 那样设置,它只是为单元格按钮标签显示白色。

我使用以下语法设置按钮标题颜色:

cell.viewAllButton.setTitleColor(UIColor(red: 192, green: 192, blue: 192, alpha: 1.0), for: .normal)

对于其他颜色,按钮标签设置成功。

【问题讨论】:

  • Duh... UIColor(red: 192/255.0, green: 192/255.0, blue: 192/255.0, alpha: 1.0)
  • @ElTomato 我不明白为什么它适用于其他颜色,你能告诉我吗?
  • @IskandarH 值超过 1 的上限为 1。例如,UIColor(red: 100, green: 0, blue: 0, alpha: 1.0) 将解析为 UIColor(red: 1, green: 0, blue: 0, alpha: 1.0)(即 red)。

标签: ios swift button cell rgb


【解决方案1】:

它应该可以工作

cell.viewAllButton.setTitleColor(UIColor(red: 192/255, green: 192/255, blue: 192/255, alpha: 1.0), for: .normal)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    相关资源
    最近更新 更多