因此,我对ClockKit复杂性有点陌生,我想知道如何为两个复杂问题制作占位符模板。
就我的准则而言:
func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKTimeIntervalTextProvider(startDate: NSDate(), endDate: NSDate())
template.body1TextProvider = CLKSimpleTextProvider(text: "Label 1", shortText: "1")
template.body2TextProvider = CLKSimpleTextProvider(text: "Label 2", shortText: 2)
handler(template)
}有人能帮忙吗?
发布于 2015-11-28 09:11:04
添加一个开关语句以返回特定的复杂情况,基于complication.family
func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
var template: CLKComplicationTemplate? = nil
switch complication.family {
case .ModularSmall:
template = nil
case .ModularLarge:
let modularLargeTemplate = CLKComplicationTemplateModularLargeStandardBody()
modularLargeTemplate.headerTextProvider = CLKTimeIntervalTextProvider(startDate: NSDate(), endDate: NSDate())
modularLargeTemplate.body1TextProvider = CLKSimpleTextProvider(text: "Label 1", shortText: "1")
modularLargeTemplate.body2TextProvider = CLKSimpleTextProvider(text: "Label 2", shortText: "2")
template = modularLargeTemplate
case .UtilitarianSmall:
template = nil
case .UtilitarianLarge:
let utilitarianLargeTemplate = CLKComplicationTemplateUtilitarianLargeFlat()
utilitarianLargeTemplate.textProvider = CLKSimpleTextProvider(text: "Label 1")
template = utilitarianLargeTemplate
case .CircularSmall:
let circularSmallTemplate = CLKComplicationTemplateCircularSmallRingText()
circularSmallTemplate.textProvider = CLKSimpleTextProvider(text: "1")
circularSmallTemplate.fillFraction = 0.5
circularSmallTemplate.ringStyle = CLKComplicationRingStyle.Closed
template = circularSmallTemplate
}
handler(template)
}https://stackoverflow.com/questions/33441489
复制相似问题