问题描述
我目前正在尝试实施一个 CLKComplicationTemplateGraphicCircularClosedGaugeImage 但由于某种原因,我的图标一直呈蓝色。
当我更改WatchFace的tintColor时,一切似乎都以正确的方式着色。但是,当我在WatchFace上禁用着色时,由于某种原因,我的图像会变成蓝色。
我在资产目录中启用了渲染模式:总是模板,因为我的图像在原始版本中只是黑色,并且在应用的其他部分着色。
let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,gaugeColor: color,fillFraction: progress)
let template = CLKComplicationTemplateGraphicCircularClosedGaugeImage(gaugeProvider: gaugeProvider,imageProvider: CLKFullColorImageProvider(fullColorImage: image))
我试图在模板上应用tintColor,并且在将图像传递给ImageProvider之前还尝试对图像应用tintColor direclty。这两个想法都不会产生预期的输出。
let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,fillFraction: progress)
let imageProvider = CLKFullColorImageProvider(fullColorImage: image)
let template = CLKComplicationTemplateGraphicCircularClosedGaugeImage(gaugeProvider: gaugeProvider,imageProvider: imageProvider)
template.tintColor = .white // this has no effect
使用 alwaysTemplate 作为呈现模式时,如何设置默认的色调颜色?
解决方法
我自己找到了一个解决方案。 我现在将图像着色为白色,并将其重新呈现为原始图像。
let imageProvider = CLKFullColorImageProvider(fullColorImage: image.withTintColor(.white,renderingMode: .alwaysTemplate).withRenderingMode(.alwaysOriginal))