两件式图像并发症

Rag*_*tto 2 xcode objective-c watchkit watchos-2 apple-watch-complication

我想显示一个多色复杂功能图标,类似于默认的计时器应用程序图标:

在此处输入图片说明

这是我用多色显示图标的代码:

CLKComplicationTemplateModularSmallStackImage* template=[[CLKComplicationTemplateModularSmallStackImage alloc]init];

template.line1ImageProvider=[CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"Complication/Modular"] 
    twoPieceImageBackground:[UIImage imageNamed:@"ComplicationForeground/Modular"] 
    twoPieceImageForeground:[UIImage imageNamed:@"ComplicationBackgroud/Modular"]];

entry = [CLKComplicationTimelineEntry entryWithDate:[NSDate date]
                                           complicationTemplate:template];
Run Code Online (Sandbox Code Playgroud)

两幅图像都有清晰的背景。如何使用 whiteColor 为中心图像着色,并使用另一种颜色为外部图像着色?

小智 5

使用该tintColor属性指定两件式图像背景的色调颜色。

例如,如果您希望两件式图像背景颜色为绿色,则可以指定:

template.line1ImageProvider.tintColor = [UIColor greenColor]; // Objective-C

template.line1ImageProvider?.tintColor = UIColor.greenColor() // Swift
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅 CLKImageProvider 类参考

两幅图像仅在多色环境中显示,并且在这些环境中优先于一幅图像。两片式图像由叠加在背景图像之上的前景图像组成。两个图像都是模板图像。ClockKit 将 tintColor 属性中的颜色应用于背景图像,如果未指定自定义颜色,则回退到底层模板中的颜色或白色。ClockKit 始终将白色应用于前景图像。在单色环境中不使用两件式图像。