[我正在尝试使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
但是,在黑暗模式下为表单:
我在做什么错:
textView.backgroundColor = .systemBackground
textView.layer.borderColor = UIColor.placeholderText.cgColor
啊,我明白了。我拥有的UITextView
位于UIViewController
中(以便更好地控制尺寸)