gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:23 26 4
gpt4 key购买 nike

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

enter image description here

最佳答案

在我看来,在 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。< br/>但是……
body1TextProvider.tintColorbody2TextProvider?.tintColor 不能像文档中那样工作,因为它不应用给定的 UIColor
向我们展示记录的行为并未在所有 textProvider 中统一应用。


然而...

我注意到,如果您将 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))

关于swift - 如何在 Modular Large Complication 中设置白色文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54780956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com