1

それで、私は ClockKit Complications の初心者で、2 つの Complications のプレースホルダー テンプレートを作成する方法を知りたいです。

これまでの私のコード:

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)

}

誰でも助けることができますか?

4

1 に答える 1

3

以下に基づいて、特定の合併症を返すために switch ステートメントを追加します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)
}
于 2015-11-28T09:11:04.350 に答える