watchOS Complication Graphic Circular

Graphic Circular

Document

8種類

CLKComplicationTemplateGraphicCircularImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "kumonosu94")!)
        
        let circularTemplate = CLKComplicationTemplateGraphicCircularImage()
        circularTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularStackImage

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

        let circularTemplate = CLKComplicationTemplateGraphicCircularStackImage()
        circularTemplate.line1ImageProvider = imageProvider
        circularTemplate.line2TextProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularStackText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let text1Provider = CLKSimpleTextProvider(text: "xyz")
        let text2Provider = CLKSimpleTextProvider(text: "Text")
        text2Provider.tintColor = UIColor.green

        let circularTemplate = CLKComplicationTemplateGraphicCircularStackText()
        circularTemplate.line1TextProvider = text1Provider
        circularTemplate.line2TextProvider = text2Provider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularClosedGaugeImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.3, 1.0]
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 1.0)
        let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "kumonosu32")!)


        let circularTemplate = CLKComplicationTemplateGraphicCircularClosedGaugeImage()
        circularTemplate.gaugeProvider = weatherGaugeProvider
        circularTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularOpenGaugeImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.3, 1.0]
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 0.8)
        let textProvider = CLKSimpleTextProvider(text: "xyz")
        textProvider.tintColor = UIColor.purple
        let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "kumonosu48")!)


        let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeImage()
        circularTemplate.gaugeProvider = weatherGaugeProvider
        circularTemplate.centerTextProvider = textProvider
        circularTemplate.bottomImageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularClosedGaugeText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.3, 1.0]
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 0.6)
        let textProvider = CLKSimpleTextProvider(text: "xyz")
        textProvider.tintColor = UIColor.gray


        let circularTemplate = CLKComplicationTemplateGraphicCircularClosedGaugeText()
        circularTemplate.gaugeProvider = weatherGaugeProvider
        circularTemplate.centerTextProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.5, 1.0]
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 0.4)
        let centerTextProvider = CLKSimpleTextProvider(text: "xyz")
        let buttomTextProvider = CLKSimpleTextProvider(text: "40%")

        let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
        circularTemplate.gaugeProvider = weatherGaugeProvider
        circularTemplate.centerTextProvider = centerTextProvider
        circularTemplate.bottomTextProvider = buttomTextProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: circularTemplate)

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

CLKComplicationTemplateGraphicCircularOpenGaugeRangeText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCircular:
        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.5, 1.0]
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 0.4)
        let centerTextProvider = CLKSimpleTextProvider(text: "xyz")
        let lowTempText = CLKSimpleTextProvider(text: "52")
        lowTempText.tintColor = UIColor.cyan
        let highTempText = CLKSimpleTextProvider(text: "89")
        highTempText.tintColor = UIColor.red

        let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeRangeText()
        circularTemplate.gaugeProvider = weatherGaugeProvider
        circularTemplate.centerTextProvider = centerTextProvider
        circularTemplate.leadingTextProvider = lowTempText
        circularTemplate.trailingTextProvider = highTempText

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

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

Swift

Posted by shi-n