watchOS Complication Utilitarian Small

Utilitarian Small

Document

4種類

CLKComplicationTemplateUtilitarianSmallFlat

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

        let utilitarianTemplate = CLKComplicationTemplateUtilitarianSmallFlat()
        utilitarianTemplate.imageProvider = imageProvider
        utilitarianTemplate.textProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: utilitarianTemplate)

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

CLKComplicationTemplateUtilitarianSmallRingImage

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

        let utilitarianTemplate = CLKComplicationTemplateUtilitarianSmallRingImage()
        utilitarianTemplate.imageProvider = imageProvider
        utilitarianTemplate.fillFraction = 0.8
        utilitarianTemplate.ringStyle = .closed
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: utilitarianTemplate)

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

ringStyle = .closed

ringStyle = .open

CLKComplicationTemplateUtilitarianSmallRingText

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

        let utilitarianTemplate = CLKComplicationTemplateUtilitarianSmallRingText()
        utilitarianTemplate.textProvider = textProvider
        utilitarianTemplate.fillFraction = 0.9
        utilitarianTemplate.ringStyle = .closed
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: utilitarianTemplate)

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

ringStyle = .closed

ringStyle = .open

CLKComplicationTemplateUtilitarianSmallSquare

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

        let utilitarianTemplate = CLKComplicationTemplateUtilitarianSmallSquare()
        utilitarianTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: utilitarianTemplate)

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

Swift

Posted by shi-n