ios - Swift 属性字符串清除背景文本

标签 ios swift xcode text fonts

我正在尝试使用 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
}()

我希望得到清晰的背景而不是灰色的背景。

带有 UIColor.clear 的图像
Link to image with UIColor.clear

尝试了 UIColor.blue,但我仍然不明白哪里出了问题
Tried doing UIColor.blue and still I don't get what's wrong

最佳答案

删除

NSAttributedString.Key.backgroundColor: UIColor.clear

来自属性字典。

添加

textView.backgroundColor = .clear

关于ios - Swift 属性字符串清除背景文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55556401/

相关文章:

ios - 如何更改 UITabBarItem 文本的颜色

ios - 从 AnyObject(NSString) 获取字符串

ios - 数百个目标,xcode 配置中的相同代码库

javascript - YouTube iframe Embed 无法控制 iPad 上的音频

iphone - UIPickerView 高度不可更改

ios - Alamofire 不会在 podfile 中使用 osx 而不是 ios

ios - 使用 Swift 更新核心数据对象

swift - 如何快速将数据转换为十六进制字符串

iphone - 如何在设备 sleep 时保持 GPS 处于全功率状态

ios - 扩展 Storyboard 中可用的对象数量