Apple Watch Complication Tint Color

时间:2017-09-25 16:36:48

标签: apple-watch apple-watch-complication

我正在尝试为复杂模板图像添加色调颜色。当我滚动选项以自定义我的表盘时,色调颜色是正确的。但是,一旦我选择并发症并返回到正常的表盘状态,颜色就会切换回白色。

- (void)getLocalizableSampleTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTemplate * __nullable complicationTemplate))handler {
  CLKComplicationTemplateModularSmallSimpleImage *modularTemplate = [[CLKComplicationTemplateModularSmallSimpleImage alloc] init];
  CLKImageProvider *imageProvider = [CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"Complication/Modular"]];
  imageProvider.tintColor  = [UIColor colorWithRed:0.412 green:0.443 blue:0.773 alpha:1.000];
  modularTemplate.imageProvider = imageProvider;
  handler(modularTemplate);
}

自: Tint is correct while customizing

选择并发症后: Tint is gone and it's back to a white image

1 个答案:

答案 0 :(得分:2)

正如David在评论中提到的,问题中的函数只处理模板,您需要在准备实际复杂数据的函数中复制相同的行为。

添加以下代码,使色调颜色持续超过选择阶段:

- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {
  CLKComplicationTemplateModularSmallSimpleImage *template = [[CLKComplicationTemplateModularSmallSimpleImage alloc] init];
  CLKImageProvider *imageProvider = [CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"Complication/Modular"]];
  imageProvider.tintColor  = [UIColor colorWithRed:0.412 green:0.443 blue:0.773 alpha:1.000];
  template.imageProvider = imageProvider;
  handler([CLKComplicationTimelineEntry entryWithDate:[NSDate date] complicationTemplate:template]);
}