Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 设置Apple Watch的颜色_Swift_Watchos_Apple Watch Complication_Clockkit - Fatal编程技术网

Swift 设置Apple Watch的颜色

Swift 设置Apple Watch的颜色,swift,watchos,apple-watch-complication,clockkit,Swift,Watchos,Apple Watch Complication,Clockkit,我正在尝试为一个模块化的大复杂度设置标题文本颜色 我已经定制的手表面使用多色 但是,当我构建并运行此代码时,标题文本颜色仍然是白色(这是默认值) 为什么颜色没有更新 private func templateForClassModularLarge(className: Schedule) -> CLKComplicationTemplateModularLargeStandardBody { let template = CLKComplicationTemplateModula

我正在尝试为一个模块化的大复杂度设置标题文本颜色

我已经定制的手表面使用多色

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

为什么颜色没有更新

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之间的值

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

UIColor(red: 1, green: 1, blue: 1, alpha: 1)
要解决此问题,只需将着色剂颜色更改为

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

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

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

UIColor(red: 1, green: 1, blue: 1, alpha: 1)
要解决此问题,只需将着色剂颜色更改为

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