簡體   English   中英

背景顏色不會改變 TextEditor 視圖

[英]Background color not change TextEditor view

//.........some other views........

       ZStack(alignment: .leading ) {
            
            Color.black.ignoresSafeArea()
            TextEditor(text: $mytext)
                .background(Color.orange)
                .padding()
                .foregroundColor(Color.gray)
                .frame(width: 362, height: 400)
            

        }

對於我應用的所有情況,背景顏色仍然是 Color.white,所以這里有什么問題? 謝謝你。

我們需要通過外觀清除默認背景顏色

    init() {
        UITextView.appearance().backgroundColor = .clear
    }

然后background修飾符在任何模式下工作

    TextEditor(text: $mytext)
        .background(Color.orange)

使用 Xcode 13.4 / iOS 15.5 測試

演示

你不能真正改變SwiftUI TextEditorbackground 任何一種材質/形狀/顏色都不能用作 SwiftUI TextEditor 的背景。

但是,您可以將 TextEditor 的顏色相乘,這提供了與一般背景(.color)相似的結果,但它並不是真正的背景顏色。

 TextEditor(text: $mytext)
            .colorMultiply(.orange) //modified
            .padding()
            .foregroundColor(Color.gray)
            .frame(width: 362, height: 400)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM