【问题标题】:Setting tintColor for Apple Watch complication为 Apple Watch 复杂功能设置 tintColor
【发布时间】:2016-04-25 21:18:43
【问题描述】:

我正在尝试为模块化大型复杂功能设置标题文本颜色。

我已经自定义表盘以使用多色。

但是,当我构建并运行此代码时,标题文本颜色仍然是白色(这是默认值)。

为什么颜色没有更新?

private func templateForClassModularLarge(className: Schedule) -> CLKComplicationTemplateModularLargeStandardBody {
    let template = CLKComplicationTemplateModularLargeStandardBody()
    let headerTextProvider = CLKSimpleTextProvider(text: "My Schedule", shortText: "Schedule")
    headerTextProvider.tintColor = UIColor(red: 101, green: 153, blue: 255, alpha: 1)
    template.headerTextProvider = headerTextProvider

    template.body1TextProvider = CLKTimeIntervalTextProvider(startDate: className.start, endDate: className.end)
    template.body2TextProvider = CLKSimpleTextProvider(text: className.description, shortText: className.shortDescription)

    return template
}

【问题讨论】:

    标签: swift watchos apple-watch-complication clockkit


    【解决方案1】:

    UIColor 参数类型为 CGFloat,指定为 0.0 到 1.0 之间的值。

    因为您的 RGB 参数大于 1,所以颜色最终为白色,即:

    UIColor(red: 1, green: 1, blue: 1, alpha: 1)
    

    要解决此问题,只需将 tintColor 更改为

    headerTextProvider.tintColor = UIColor(red: 101/255, green: 153/255, blue: 255/255, alpha: 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 2016-03-17
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多