watchOS Complication Modular Small Text

Modular Small Text

Document

4種類

CLKComplicationTemplateModularSmallColumnsText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularSmall:
        let textR1C1Provider = CLKSimpleTextProvider(text: "11")
        let textR1C2Provider = CLKSimpleTextProvider(text: "12")
        let textR2C1Provider = CLKSimpleTextProvider(text: "21")
        let textR2C2Provider = CLKSimpleTextProvider(text: "22")
        
        let modularTemplate = CLKComplicationTemplateModularSmallColumnsText()
        modularTemplate.column2Alignment = .leading
        modularTemplate.highlightColumn2 = false
        modularTemplate.row1Column1TextProvider = textR1C1Provider
        modularTemplate.row1Column2TextProvider = textR1C2Provider
        modularTemplate.row2Column1TextProvider = textR2C1Provider
        modularTemplate.row2Column2TextProvider = textR2C2Provider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

column2Alignment = .leading、highlightColumn2 = false

column2Alignment = .trailing、highlightColumn2 = true

CLKComplicationTemplateModularSmallRingText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularSmall:
        let textProvider = CLKSimpleTextProvider(text: "xyz")
        
        let modularTemplate = CLKComplicationTemplateModularSmallRingText()
        modularTemplate.fillFraction = 0.9
        modularTemplate.ringStyle = .closed
        modularTemplate.textProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

ringStyle = .closed

ringStyle = .open

CLKComplicationTemplateModularSmallSimpleText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularSmall:
        let textProvider = CLKSimpleTextProvider(text: "Text")
        
        let modularTemplate = CLKComplicationTemplateModularSmallSimpleText()
        modularTemplate.textProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

CLKComplicationTemplateModularSmallStackText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .modularSmall:
        let textLine1Provider = CLKSimpleTextProvider(text: "Text")
        let textLine2Provider = CLKSimpleTextProvider(text: "xyz")
        
        let modularTemplate = CLKComplicationTemplateModularSmallStackText()
        modularTemplate.line1TextProvider = textLine1Provider
        modularTemplate.line2TextProvider = textLine2Provider
        modularTemplate.highlightLine2 = false
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

highlightLine2 = false

highlightLine2 = true

Swift

Posted by shi-n