watchOS Complication Modular Large Body

Modular Large Body

Document

2種類

CLKComplicationTemplateModularLargeStandardBody

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularLarge:
        let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "book28")!)
        let textHeaderProvider = CLKSimpleTextProvider(text: "Header")
        let textBody1Provider = CLKSimpleTextProvider(text: "Text Text Text Text")
        let textBody2Provider = CLKSimpleTextProvider(text: "xyz ___ xyz ___ xyz")

        let modularTemplate = CLKComplicationTemplateModularLargeStandardBody()
        modularTemplate.headerImageProvider = imageProvider
        modularTemplate.headerTextProvider = textHeaderProvider
        modularTemplate.body1TextProvider = textBody1Provider
        modularTemplate.body2TextProvider = textBody2Provider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

        handler(entry)
    default:
        handler(nil)
    }
}

CLKComplicationTemplateModularLargeTallBody

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularLarge:
        let textHeaderProvider = CLKSimpleTextProvider(text: "Header")
        let textBodyProvider = CLKSimpleTextProvider(text: "Text Text")

        let modularTemplate = CLKComplicationTemplateModularLargeTallBody()
        modularTemplate.headerTextProvider = textHeaderProvider
        modularTemplate.bodyTextProvider = textBodyProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

        handler(entry)
    default:
        handler(nil)
    }
}

Swift

Posted by shi-n