watchOS Complication Circular Small Image

Circular Small Image

Document

3種類

CLKComplicationTemplateCircularSmallRingImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .circularSmall:
        let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "questionnaire48")!)

        let circularTemplate = CLKComplicationTemplateCircularSmallRingImage()
        circularTemplate.imageProvider = imageProvider
        circularTemplate.ringStyle = .closed
        circularTemplate.fillFraction = 0.7

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

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

CLKImageProviderは単色画像でないと、うまく表示されません。

CLKComplicationTemplateCircularSmallSimpleImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .circularSmall:
        let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "questionnaire48")!)

        let circularTemplate = CLKComplicationTemplateCircularSmallSimpleImage()
        circularTemplate.imageProvider = imageProvider

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

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

CLKComplicationTemplateCircularSmallStackImage

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

        let circularTemplate = CLKComplicationTemplateCircularSmallStackImage()
        circularTemplate.line1ImageProvider = imageProvider
        circularTemplate.line2TextProvider = textProvider

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

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

Swift

Posted by shi-n