繁体   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