watchOS Complication Extra Large Image

Extra Large Image

Document

3種類

CLKComplicationTemplateExtraLargeRingImage

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

        let extraLargeTemplate = CLKComplicationTemplateExtraLargeRingImage()
        extraLargeTemplate.imageProvider = imageProvider
        extraLargeTemplate.ringStyle = .closed
        extraLargeTemplate.fillFraction = 0.5

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

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

色は盤面カスタマイズで指定した色が反映されます。

CLKComplicationTemplateExtraLargeSimpleImage

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

        let extraLargeTemplate = CLKComplicationTemplateExtraLargeSimpleImage()
        extraLargeTemplate.imageProvider = imageProvider

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

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

CLKComplicationTemplateExtraLargeStackImage

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

        let extraLargeTemplate = CLKComplicationTemplateExtraLargeStackImage()
        extraLargeTemplate.highlightLine2 = false
        extraLargeTemplate.line1ImageProvider = imageProvider
        extraLargeTemplate.line2TextProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: extraLargeTemplate)

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

highlightLine2 = false

highlightLine2 = true

Swift

Posted by shi-n