iOS WatchOS5 how to customize title in GraphicRectangular complication?

400 Views Asked by At

I want to remove text from my graphic rectangular complication, or set it to empty string. By default it is the app name. I tried to set display name to " " within watchKit plist file, but that did not seem to change it.

How do I remove text from my graphic rectangular WatchOS5 complication?

I see that there's some way to get (assign?) a CLKTextProvider as described here: https://developer.apple.com/documentation/clockkit/clktextprovider However, it seems to involve adding a localizable strings file and I don't want to mess with this if there's an easier way to get image only for the CLKComplicationTemplateGraphicRectangularLargeImage

    func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
        // This method will be called once per supported complication, and the results will be cached


        if complication.family == .graphicRectangular {
            let template =  GraphicTemplate()
            template.textProvider = CLKSimpleTextProvider.init(text: "")
            handler(template)
        }else {
            handler(nil)
        }
    }


class GraphicTemplate: CLKComplicationTemplateGraphicRectangularLargeImage {

}
1

There are 1 best solutions below

0
On

You don't need to mess with localizable strings (phew).

There are two places you'll need to set up the appearance of the complication.

  1. The sample template - this is displayed to the user as they're customizing a face and scrolling through the list of available complications. You provide this sample in the getLocalizableSample(for: withHandler:) method per family of complication, as you show in your question.

  2. The actual live complication shown on the face, which you provide in the getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) method of the CLKComplicationDataSource.

In both places you'll need to return the template with a text provider (you'll crash on runtime if not), although it's fine to return an empty string. This should remove the app name.

    let template = CLKComplicationTemplateGraphicRectangularLargeImage()
    template.textProvider = CLKSimpleTextProvider.init(text: "")
    template.imageProvider = CLKFullColorImageProvider(fullColorImage: myImage)
    return template

(By the way, have you seen the recent Apple Tech Talk about complications for watch os5? It's a good one ).