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

问题描述 投票:3回答:1

我无法为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))

enter image description here

swift watchkit apple-watch-complication
1个回答
1
投票

在我看来好像在tintColor上应用CLKSimpleTextProvider有一个bug或者一些无证的细微差别。

根据CLKSimpleTextProvidertintColor文件:

tintColor

用于文本的色调颜色。

讨论

在支持自定义颜色的钟面上,此颜色将应用于文本提供程序中的文本。

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

现在......在选择多色模块化表盘之后,我们可以观察到headerTextProvider.tintColor的工作原理已经记录并且应用了指定的UIColor。 但... body1TextProvider.tintColorbody2TextProvider?.tintColor没有记录,因为它不适用给定的UIColor。 向我们显示所记录的行为未在所有textProviders中统一应用。


然而...

我注意到,如果你将CLKComplicationTemplatetintColor设置为某种东西,那么body1TextProviderbody2TextProvider会变成白色,即使你试图设置另一种颜色,如蓝色/黄色/等。

幸运的是,你想要它是白色的,所以简单的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))
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.