2017-09-25 98 views
1

我正在嘗試爲複雜模板圖像添加色調顏色。當我滾動選項來自定義我的錶盤時,色調是正確的。但是,一旦我選擇複雜功能並返回正常錶盤狀態,顏色將切換回白色。Apple Watch Complication Tint Color

- (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

+0

在你的問題的功能只選擇一種併發症時所顯示的__template__的照顧。您需要在準備實際複雜數據的函數中複製相同的行爲。 –

+0

@DávidPásztor謝謝。這就是訣竅! – dyah

回答

1

當大衛在評論中提到的,問題的功能只照顧模板的,你需要在準備實際複雜數據的函數中複製相同的行爲。

添加以下代碼,以使着色顏色堅持過去的選擇階段:

- (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]); 
}