我正在尝试进行复杂的设计以显示鼓舞人心的信息。我认为我首先要进行角部并发症并显示硬编码的消息,但我什至不知道如何显示。这是到目前为止我没有阅读其他文章和Apple文档的内容。我正在使用“边角堆栈”文本模板。
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
let date = Date()
var template: CLKComplicationTemplate!
template = CLKComplicationTemplateGraphicCornerStackText()
var firstTextProvider = CLKSimpleTextProvider(text: "Don't Worry")
var secondTextProvider = CLKSimpleTextProvider(text: "Be Happy")
template.outerTextProvider = CLKSimpleTextProvider(text: "Don't Worry")
template.innerTextProvider = secondTextProvier
let entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
handler(entry)
}
您应该实现getLocalizableSampleTemplate
方法:
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
switch complication.family {
case .graphicCorner:
let template = CLKComplicationTemplateGraphicCornerStackText()
template.innerTextProvider = CLKSimpleTextProvider(text: "innerT")
template.outerTextProvider = CLKSimpleTextProvider(text: "outerT")
handler(template)
default:
handler(nil)
}
}
您还应该考虑在switch case
类的所有方法中使用ComplicationController
,但这不是必需的:
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
switch complication.family {
case .graphicCorner:
let template = CLKComplicationTemplateGraphicCornerStackText()
template.innerTextProvider = CLKSimpleTextProvider(text: "innerT")
template.outerTextProvider = CLKSimpleTextProvider(text: "outerT")
handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
default:
handler(nil)
}
}
请确保您使用的是正确的表面,GraphicCornerStack-Complication仅可用于“圆形” -Infograph-表面的角落。
您还应注意项目的选定并发症。如果打开WatchKit扩展目标的“常规设置”,则应该看到一个名为“并发症配置”的区域,并且应该在列表中选择正确的并发症(在您的情况下为“图形角”)。如果您无法通过switch case
语句处理其他可能的复杂性,则在这里不应选择多个可能的复杂性。