watchOS Complication Modular Small Image

Modular Small Image

Document

3種類

CLKComplicationTemplateModularSmallRingImage

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

        let modularTemplate = CLKComplicationTemplateModularSmallRingImage()
        modularTemplate.ringStyle = .closed
        modularTemplate.fillFraction = 0.7
        modularTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

ringStyle = .closed

ringStyle = .open

CLKComplicationTemplateModularSmallSimpleImage

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

        let modularTemplate = CLKComplicationTemplateModularSmallSimpleImage()
        modularTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: modularTemplate)

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

CLKComplicationTemplateModularSmallStackImage

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

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

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

highlightLine2 = false

highlightLine2 = true

Swift

Posted by shi-n