SwiftUI视图背景中的UITextView和深色模式(窗体)的边框颜色

问题描述 投票:2回答:1

[我正在尝试使UITextView与(SwiftUI)TextField看起来相同,UITextView代码如下:

...
func makeUIView(context: UIViewRepresentableContext<TextView>) -> UITextView {
  let textView = UITextView()

  textView.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body) 
  textView.text = placeholderText
  textView.textColor = .placeholderText
  textView.backgroundColor = .systemBackground
  textView.layer.borderColor = UIColor.placeholderText.cgColor
  textView.layer.borderWidth = 1
  textView.layer.cornerRadius = 6

  return textView
}
...

完整代码类似于this

在表单中,在轻度模式下看起来不错:enter image description here

但是,在黑暗模式下为表单:

enter image description here

我在做什么错:

textView.backgroundColor = .systemBackground
textView.layer.borderColor = UIColor.placeholderText.cgColor
ios swift xcode uitextview swiftui
1个回答
0
投票

啊,我明白了。我拥有的UITextView位于UIViewController中(以便更好地控制尺寸)

© www.soinside.com 2019 - 2024. All rights reserved.