如何在 Modular Large Complication 中设置白色文本?

How set white color text in Modular Large Complication?

我无法为 body1TextProviderbody2TextProvider 设置白色文本颜色。只有灰色可供选择。

我的代码:

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

在我看来,在 CLKSimpleTextProvider.

上应用 tintColor 似乎存在错误或一些未记录的细微差别

根据 CLKSimpleTextProvidertintColor 的文档:

tintColor

The tint color to use for text.

Discussion

On clock faces that support custom colors, this color is applied to the text in your text provider.

Ref: https://developer.apple.com/documentation/clockkit/clktextprovider/1627929-tintcolor

现在...在选择多色模块化表盘后,我们可以观察到 headerTextProvider.tintColor 按照记录工作并且确实应用了指定的 UIColor
但是...
body1TextProvider.tintColorbody2TextProvider?.tintColor 不能像记录的那样工作,因为它不应用给定的 UIColor.
向我们展示记录的行为并未在所有 textProvider 中统一应用。


然而...

我注意到,如果您将 CLKComplicationTemplatetintColor 设置为某个值,那么 body1TextProviderbody2TextProvider 会变成白色,即使您尝试设置另一种颜色,例如 blue/yellow/etc.

幸运的是,您想要它是白色的 modularLarge.tintColor = .red(或 UIColor 匹配您的主题)将为您提供白色正文。


总结:

无需进行以下操作(remove/keep,无所谓):

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