我正在尝试让一张图片在Apple Watch的表面上显示为一个复杂的图像。我已经尝试过.jpg和.png文件。我相信让复杂性工作的代码是正确的,但出于某种原因,图像是这样白色的:

我的代码如下:
var template: CLKComplicationTemplate? = nil
let temporaryTemplate = CLKComplicationTemplateModularSmallSimpleImage()
let theImage = UIImage(named: "testImage")!.imageWithRenderingMode(.AlwaysTemplate)
let imager = CLKImageProvider(onePieceImage: theImage)
temporaryTemplate.imageProvider = imager
template = temporaryTemplate我知道对于并发症,图像被认为是"alpha-only“的,但我认为这是系统自动完成的。我是不是漏掉了一个步骤?
发布于 2015-12-03 02:29:59
你是对的,你的代码都是正确的,证据是白色方块,这意味着问题就在图像中。
只要从12:10开始仔细观察the video就可以了。简而言之,你必须创建一个带有alpha通道的单色图像,而系统当然不能为你做这件事。下面是一个例子,你可以把它代替你的图片,然后看看结果:

另外,请附上您的图像来检查它。
发布于 2015-12-02 15:13:49
我使用了指南中提到的用于复杂化的图像。下面是我的代码。它对我来说工作得很好,删除渲染模式部分并尝试。我已经附上了一个我使用的样本图像。

let template = CLKComplicationTemplateModularLargeStandardBody()
let image = UIImage(named: imageName[![enter image description here][1]][1])
template.headerImageProvider =
CLKImageProvider(onePieceImage: image!)
template.headerTextProvider = CLKSimpleTextProvider(text: headerText)发布于 2018-05-15 13:54:05
我承认我不会看WWDC的视频或者苹果的文档。我尝试了一些东西,通常都很管用。
因此,在看到这个bug之后,我有了一个想法,它成功了。我必须返回时间线条目,即使我不支持向前或向后。
解决了应用图标出现白盒图像的问题。
- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication
withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {
[self getLocalizableSampleTemplateForComplication:complication
withHandler:^(CLKComplicationTemplate * _Nullable complicationTemplate) {
CLKComplicationTimelineEntry* entry = [CLKComplicationTimelineEntry entryWithDate:[NSDate date]
complicationTemplate:complicationTemplate];
handler(entry);
}];}https://stackoverflow.com/questions/34035443
复制相似问题