我的Apple Watch应用程序有一个复杂功能,我想添加第二种样式。我提出了一个非常基本的原型,但是在表盘上看不到可供选择的原型。因此,我正在尝试解决此问题:
我的应用程序可以支持多个并发症吗? 我可以同时在表盘上运行两种并发症吗?(或者是非此即彼,如果我有一个,iOS不会显示第二个复杂性?)我尝试添加一个新的表盘,但不允许我这样做。
CLKComplicationTemplateModularSmallRingText
是ModularSmall
型并发症的有效模板吗?
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
if complication.family == .modularSmall {
let template = CLKComplicationTemplateModularSmallRingText()
template.ringStyle = .open
template.fillFraction = 0.3
let testProvider = CLKSimpleTextProvider(text: "TST", shortText: "S")
sleep.tintColor = UIColor.green
template.textProvider = testProvider
template.tintColor = UIColor.green
let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
// Pass the entry to ClockKit.
handler(entry)
}
else if complication.family == .graphicRectangular {
let template = CLKComplicationTemplateGraphicRectangularLargeImage()
//this complication works...
}
占位符模板现在是相同的:
func getPlaceholderTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// Pass the template to ClockKit.
if complication.family == .modularSmall {
let template = CLKComplicationTemplateModularSmallRingText()
//...
我在并发症占位符文件中看到一个错误(但是我正在44毫米设备上进行测试)-将其修复并查看发生了什么。我是否为模块化并发症返回了错误的图像或错误的模板类型?我想要一个圆环规
答案 0 :(得分:0)
原来,我被Apple的文档误导了。我需要使用GraphicCircular complication(WatchOS5中的新增功能)类型,而不是模块化(旧表盘)
func circularTemplate() -> CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText{
let template = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
let gauge = CLKSimpleGaugeProvider(style: .ring, gaugeColor: UIColor.green), fillFraction: 0.3)
template.gaugeProvider = gauge
let random = arc4random() % 999
let middle = CLKSimpleTextProvider(text: "4.5", shortText: "4")
middle.tintColor = kRGBColorFromHex(0x657585)
template.tintColor = kRGBColorFromHex(0x657585)
template.centerTextProvider = middle
let bottom = CLKSimpleTextProvider(text: "-\(random)", shortText: "1..")
template.bottomTextProvider = bottom
return template
}
新样式: