Met*_*man 7 swift watchkit apple-watch-complication
我无法为body1TextProvider和body2TextProvider设置白色文本颜色。仅灰色可供选择。
我的代码:
let modularLarge = CLKComplicationTemplateModularLargeStandardBody()
modularLarge.headerTextProvider = CLKSimpleTextProvider(text: dateText.capitalized)
modularLarge.headerTextProvider.tintColor = self.tintColor
modularLarge.body1TextProvider = CLKSimpleTextProvider(text: timeText)
modularLarge.body2TextProvider = CLKSimpleTextProvider(text: "00:00")
modularLarge.body1TextProvider.tintColor = self.whiteColor
modularLarge.body2TextProvider?.tintColor = self.whiteColor
handler(CLKComplicationTimelineEntry(date: Date(),complicationTemplate: modularLarge))
Run Code Online (Sandbox Code Playgroud)
在我看来,似乎要么存在错误,要么存在一些未记录的细微tintColor差别CLKSimpleTextProvider。
根据 的CLKSimpleTextProvider文档tintColor:
色调颜色
用于文本的色调颜色。
讨论
在支持自定义颜色的钟面上,此颜色将应用于文本提供程序中的文本。
参考:https://developer.apple.com/documentation/clockkit/clktextprovider/1627929-tintcolor
现在...选择多色模块化表盘后,我们可以观察到其headerTextProvider.tintColor工作原理如文档所示,并且确实应用了指定的UIColor.
但是...
body1TextProvider.tintColor并且body2TextProvider?.tintColor不能按记录工作,因为它不应用给定的UIColor。
向我们表明记录的行为并未统一应用于所有textProviders。
我注意到,如果您将CLKComplicationTemplate'设置tintColor为某种颜色,那么即使您尝试设置另一种颜色(例如蓝色/黄色/等),也会变成白色body1TextProvider。body2TextProvider
幸运的是,您希望它是白色的,所以简单地modularLarge.tintColor = .red(或UIColor匹配您的主题)将为您提供白色的正文文本。
无需执行以下操作(删除/保留,无关紧要):
modularLarge.body1TextProvider.tintColor = self.whiteColor
modularLarge.body2TextProvider?.tintColor = self.whiteColor
Run Code Online (Sandbox Code Playgroud)
相反,请在调用之前执行此操作handler:
modularLarge.tintColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
let modularLarge = CLKComplicationTemplateModularLargeStandardBody()
modularLarge.tintColor = .red //do this
modularLarge.headerTextProvider = CLKSimpleTextProvider(text: dateText.capitalized)
modularLarge.headerTextProvider.tintColor = self.tintColor
modularLarge.body1TextProvider = CLKSimpleTextProvider(text: timeText)
modularLarge.body2TextProvider = CLKSimpleTextProvider(text: "00:00")
handler(CLKComplicationTimelineEntry(date: Date(),complicationTemplate: modularLarge))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
272 次 |
| 最近记录: |