Setting tintColor for Apple Watch complication

心已入冬 提交于 2019-12-24 17:12:20

问题


I am trying to set the header text color for a Modular Large complication.

I have already customized the watch face to use Multicolor.

However, when I build and run this code, the header text color is still white (which is the default).

Why isn't the color updating?

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
}

回答1:


UIColor parameter types are CGFloat, specified as a value from 0.0 to 1.0.

Because your RGB parameters are greater than 1, the color ends up being white, which would be:

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

To fix this issue, simply change your tintColor to

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


来源:https://stackoverflow.com/questions/36851254/setting-tintcolor-for-apple-watch-complication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!