iOS16では背景色をつける場合はscrollContentBackgroundモディファイアを使う。
※iOS15以前は
init() {
UITextView.appearance().backgroundColor = .clear
}
と書いていたが、iOS16ではこの機能は使えない。
struct ContentView: View {
@State var textEditor: String = "ああああ"
var body: some View {
ZStack {
Color.brown.opacity(0.5)
TextEditor(text: $textEditor)
.frame(width: 100, height: 100)
.scrollContentBackground(.hidden)
.background(.white, in: RoundedRectangle(cornerRadius: 30.0))
.overlay(
ZStack {
RoundedRectangle(cornerRadius: 30.0)
.stroke(
LinearGradient(
colors: [
Color(red: 254 / 255, green: 212 / 255, blue: 117 / 255)
,Color(red: 229 / 255, green: 61 / 255, blue: 93 / 255)
,Color(red: 194 / 255, green: 49 / 255, blue: 134 / 255)
],
startPoint: .bottomLeading,
endPoint: .topTrailing
),
lineWidth: 2
)
}
)
}
}
}
