我无法为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))
在我看来好像在tintColor
上应用CLKSimpleTextProvider
有一个bug或者一些无证的细微差别。
根据CLKSimpleTextProvider
的tintColor
文件:
tintColor
用于文本的色调颜色。
讨论
在支持自定义颜色的钟面上,此颜色将应用于文本提供程序中的文本。
参考:https://developer.apple.com/documentation/clockkit/clktextprovider/1627929-tintcolor
现在......在选择多色模块化表盘之后,我们可以观察到headerTextProvider.tintColor
的工作原理已经记录并且应用了指定的UIColor
。
但...
body1TextProvider.tintColor
和body2TextProvider?.tintColor
没有记录,因为它不适用给定的UIColor
。
向我们显示所记录的行为未在所有textProvider
s中统一应用。
我注意到,如果你将CLKComplicationTemplate
的tintColor
设置为某种东西,那么body1TextProvider
和body2TextProvider
会变成白色,即使你试图设置另一种颜色,如蓝色/黄色/等。
幸运的是,你想要它是白色的,所以简单的modularLarge.tintColor = .red
(或匹配你的主题的UIColor
)将为你提供白色的身体文本。
无需执行以下操作(删除/保留,无所谓):
modularLarge.body1TextProvider.tintColor = self.whiteColor
modularLarge.body2TextProvider?.tintColor = self.whiteColor
相反,在调用handler
之前执行此操作:
modularLarge.tintColor = UIColor.red
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))