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

Check out our book!

Integrating SwiftUI into UIKit Apps

Integrating SwiftUI intoUIKit Apps


A detailed guide on gradually adopting SwiftUI in UIKit projects.

  • Discover various ways to add SwiftUI views to existing UIKit projects
  • Use Xcode previews when designing and building UI
  • Update your UIKit apps with new features such as Swift Charts and Lock Screen widgets
  • Migrate larger parts of your apps to SwiftUI while reusing views and controllers built in UIKit