iOS 16 beta 4 broke UITextView.appearance().backgroundColor

in iOS 16 beta 4, the following code ignores the UITextView.appearance().backgroundColor = .clear

struct ContentView: View {
	@State var text = "Type something here."
	
	var body: some View {
		ZStack {
			Color.blue.ignoresSafeArea()
			TextEditor(text: $text)
				.frame(height: 100)
				.padding([.leading, .trailing], 40)
		}
		.onAppear {
			UITextView.appearance().backgroundColor = .clear
		}
	}
}

Earlier, I had assumed it was Xcode 14 beta 4 - but further investigation shows that it's the new iOS beta.

I would obviously prefer that TextEditor correctly handle it's own .background() method, but in the meantime, any ideas for a workaround?

Answered by CryptoKoa in 723184022

Work-around found!

I found this in the release notes:

Added View.scrollContentBackground, which permits customization of background colors for scrollable views like List. (45928055)

And so here’s the new version…

struct ContentView: View {
	@State var text = "Type something here."
	
	var body: some View {
		ZStack {
			Color.blue.ignoresSafeArea()

			if #available(iOS 16.0, *) {
				TextEditor(text:$text)
					.multilineTextAlignment(.center)
					.scrollContentBackground(Visibility.hidden)    // new technique for iOS 16
					.frame(height: 100)
					.padding([.leading, .trailing], 40)
			} else {
				// Fallback on earlier versions
				TextEditor(text:$text)
					.multilineTextAlignment(.center)
					.frame(height: 100)
					.padding([.leading, .trailing], 40)
			}
		}
		.onAppear {
			// Fallback on earlier versions
			UITextView.appearance().backgroundColor = .clear
		}
	}
}

FYI: I submitted FB10908604 regarding this

iOS 16 beta 5 continues to exhibit this bug

Accepted Answer

Work-around found!

I found this in the release notes:

Added View.scrollContentBackground, which permits customization of background colors for scrollable views like List. (45928055)

And so here’s the new version…

struct ContentView: View {
	@State var text = "Type something here."
	
	var body: some View {
		ZStack {
			Color.blue.ignoresSafeArea()

			if #available(iOS 16.0, *) {
				TextEditor(text:$text)
					.multilineTextAlignment(.center)
					.scrollContentBackground(Visibility.hidden)    // new technique for iOS 16
					.frame(height: 100)
					.padding([.leading, .trailing], 40)
			} else {
				// Fallback on earlier versions
				TextEditor(text:$text)
					.multilineTextAlignment(.center)
					.frame(height: 100)
					.padding([.leading, .trailing], 40)
			}
		}
		.onAppear {
			// Fallback on earlier versions
			UITextView.appearance().backgroundColor = .clear
		}
	}
}

This seems to be ignored on XCode 14.2 / iOS 16 (an M1 machine) even though I set a deployment target of 15, and I cannot use scrollContentBackground as it's iOS 16 only. Not sure what to do as a workaround.

iOS 16 beta 4 broke UITextView.appearance().backgroundColor
 
 
Q