为Apple Watch并发症设置tintColor [英] Setting tintColor for Apple Watch complication

查看:113
本文介绍了为Apple Watch并发症设置tintColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Modular Large并发症设置标题文本颜色.

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).

为什么颜色不更新?

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
}

推荐答案

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

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

由于您的RGB参数大于1,因此颜色最终变为白色,即:

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)

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

To fix this issue, simply change your tintColor to

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

这篇关于为Apple Watch并发症设置tintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆