我正在尝试使用 NSMutableAttributedString 制作文本标题,但是在属性字典中,我相信我有正确的代码,但是当我运行代码时,总是有灰色背景,我可能做错了什么?或者我可能会遗漏什么?
let titleTextView: UITextView = {
let textView = UITextView()
let attributedText = NSMutableAttributedString(string: "Wake Up Happy", attributes: [NSAttributedString.Key.font: UIFont.init(name: "Marker Felt", size: 40)!, NSAttributedString.Key.backgroundColor: UIColor.clear])
textView.attributedText = attributedText
textView.textAlignment = .center
textView.isEditable = false
textView.isScrollEnabled = false
textView.translatesAutoresizingMaskIntoConstraints = false
return textView
}()
我希望得到清晰的背景而不是灰色的背景。
最佳答案
删除
NSAttributedString.Key.backgroundColor: UIColor.clear
来自属性字典。
添加
textView.backgroundColor = .clear
关于ios - Swift 属性字符串清除背景文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55556401/