watchOS Complication Circular Small Text

Circular Small Text

Document

3種類

CLKComplicationTemplateCircularSmallRingText

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

        let circularTemplate = CLKComplicationTemplateCircularSmallRingText()
        circularTemplate.textProvider = textProvider
        circularTemplate.ringStyle = .open
        circularTemplate.fillFraction = 0.9
        circularTemplate.tintColor = UIColor.red

        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateCircularSmallSimpleText

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

        let circularTemplate = CLKComplicationTemplateCircularSmallSimpleText()
        circularTemplate.textProvider = textProvider

        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateCircularSmallStackText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .circularSmall:
        let line1TextProvider = CLKSimpleTextProvider(text: "Text")
        let line2TextProvider = CLKSimpleTextProvider(text: "xyz")

        let circularTemplate = CLKComplicationTemplateCircularSmallStackText()
        circularTemplate.line1TextProvider = line1TextProvider
        circularTemplate.line2TextProvider = line2TextProvider

        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

Swift

Posted by shi-n