Black Friday deal: 30% off our book "Integrating SwiftUI into UIKit apps"! Learn more ...Black Friday deal:30% off "Integrating SwiftUI into UIKit apps" >>
Quick Tip Icon
Quick Tip

Change TextEditor background in iOS 16

Starting from iOS 16 we can set a custom background for TextEditor in SwiftUI using a combination of scrollContentBackground() and background() view modifiers. We first have to hide the default background on TextEditor by applying scrollContentBackground(.hidden), otherwise our custom background won't be visible. Then we can easily set a new background with the background() method.

struct ContentView: View {
    @State private var text = "Some text"
    var body: some View {
        TextEditor(text: $text)
            .frame(width: 300, height: 200)
Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover
Black Friday offer
Our book "Integrating SwiftUI into UIKit apps" is now 30% off!

Discover various ways to adopt SwiftUI in existing UIKit projects and take full advantage of the new iOS 16 frameworks and APIs such as Swift Charts.

The offer is active until the 1st of December.