Changing the text rendering behavior
Handling texts on screen was also a very mature area where UIKit provided great frameworks such as TextKit. We could manipulate texts and create almost any effect that we wanted.
In iOS 18, Apple introduced TextRenderer, a protocol that can help us change the default behavior of our texts in SwiftUI.
Let’s say that we want a title with a different opacity for each line and even rotate the lines a bit. This creates a nice effect for the titles in our app. So, let’s see how to do that in SwiftUI:
struct CustomTextRenderer: TextRenderer { func draw(layout: Text.Layout, in ctx: inout GraphicsContext) { for (index, line) in layout.enumerated() { ctx.opacity = Double(index + 1) * 0.1 ctx...