watchOS Complication Graphic Corner

Apple Document

Developing Complications for Apple Watch Series 4

Graphic Corner

Document

5種類

CLKComplicationTemplateGraphicCornerGaugeText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCorner:
        let lowTempText = CLKSimpleTextProvider(text: "52")
        lowTempText.tintColor = UIColor.cyan
        let highTempText = CLKSimpleTextProvider(text: "89")
        highTempText.tintColor = UIColor.red
        let currentTempText = CLKSimpleTextProvider(text: "72")

        let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
        let weatherColorLocations = [0.0, 0.6, 1.0]
        let cornerTemplate = CLKComplicationTemplateGraphicCornerGaugeText()
        let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                            gaugeColors: weatherColors,
                                                            gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                            fillFraction: 0.7)
        cornerTemplate.gaugeProvider = weatherGaugeProvider
        cornerTemplate.leadingTextProvider = lowTempText
        cornerTemplate.trailingTextProvider = highTempText
        cornerTemplate.outerTextProvider = currentTempText
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)

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

現在値表現

8行目:外側表示テキスト
16行目:リング位置

外側表示テキストとリング位置に現在値を表示する場合は、両方に設定する必要がある

CLKSimpleGaugeProvider style .ring

CLKSimpleGaugeProvider style .fill

CLKComplicationTemplateGraphicCornerStackText

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCorner:
        let outerTextProvider = CLKSimpleTextProvider(text: "Outer")
        outerTextProvider.tintColor = UIColor.white
        let innerTextProvider = CLKSimpleTextProvider(text: "Inner")
        innerTextProvider.tintColor = UIColor.orange

        let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
        cornerTemplate.outerTextProvider = outerTextProvider
        cornerTemplate.innerTextProvider = innerTextProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)

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

CLKComplicationTemplateGraphicCornerCircularImage

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

        let cornerTemplate = CLKComplicationTemplateGraphicCornerCircularImage()
        cornerTemplate.imageProvider = imageProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)

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

CLKComplicationTemplateGraphicCornerGaugeImage

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCorner:
        let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "kumonosu44")!)
            let lowTempText = CLKSimpleTextProvider(text: "52")
            lowTempText.tintColor = UIColor.cyan
            let highTempText = CLKSimpleTextProvider(text: "89")
            highTempText.tintColor = UIColor.red

            let weatherColors = [UIColor.cyan, UIColor.yellow, UIColor.red]
            let weatherColorLocations = [0.0, 0.6, 1.0]
            let weatherGaugeProvider = CLKSimpleGaugeProvider(style: .ring,
                                                                gaugeColors: weatherColors,
                                                                gaugeColorLocations: weatherColorLocations as [NSNumber],
                                                                fillFraction: 0.7)

        let cornerTemplate = CLKComplicationTemplateGraphicCornerGaugeImage()
        cornerTemplate.imageProvider = imageProvider
        cornerTemplate.gaugeProvider = weatherGaugeProvider
        cornerTemplate.leadingTextProvider = lowTempText
        cornerTemplate.trailingTextProvider = highTempText
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)

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

CLKComplicationTemplateGraphicCornerTextImage

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

        let cornerTemplate = CLKComplicationTemplateGraphicCornerTextImage()
        cornerTemplate.imageProvider = imageProvider
        cornerTemplate.textProvider = textProvider
        
        let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)

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

Swift

Posted by shi-n