watchOS: Complications

Feb 7 2023 · Swift 5.6, watchOS 8.5, Xcode 13

Part 2: Tinted & Custom Complications

10. Tint SwiftUI Complications

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Tint Complications Next episode: 11. Build a SwiftUI View for a Complication

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

SwiftUI graphic complication views also support tinting but with a different syntax.

Image("full")

Desaturation

By default, SwiftUI complications will be desaturated, like the non-SwiftUI versions.

import ClockKit
CLKComplicationTemplateGraphicExtraLargeCircularView(
  HappyComplication()
)
  .previewContext()
  ForEach(CLKComplicationTemplate.PreviewFaceColor.allColors) {
    CLKComplicationTemplateGraphicExtraLargeCircularView(
      HappyComplication()
    )
    .previewContext(faceColor: $0)
  }

Layered

To use layered tinting, change the image name from full to outlines.

Image("outlines")
.complicationForeground()
ZStack {
  Circle()
  ...
}
    CLKComplicationTemplateGraphic🟩RectangularFullView(

Rendering modes

There will be times when you still want a bit more control, depending on whether the user tints the watch face.

@Environment(\.complicationRenderingMode) var renderingMode
ZStack {
  🟩if renderingMode == .fullColor {
    Image("full")
      .complicationForeground()
  }
  // previous code
}
  if renderingMode == .fullColor {
...
  } else {
    Circle()

    Image("outlines")
      .complicationForeground()
  }
.fill(LinearGradient(
  gradient: Gradient(
    colors: [.pink.opacity(1), .teal.opacity(0.1)]
  ),
  startPoint: .top,
  endPoint: .bottom))
Image("background")

Update the complication controller

So far, you’ve performed all of your previewing of the complication from Xcode’s Canvas.

import SwiftUI
let template = CLKComplicationTemplateGraphicExtraLargeCircularView(
  HappyComplication()
)

return .init(date: Date.now, complicationTemplate: template)