【问题标题】:Setting textView.typingAttributes foreground color in Swift 4在 Swift 4 中设置 textView.typingAttributes 前景色
【发布时间】:2018-01-05 13:00:53
【问题描述】:

我正在使用以下方法在 Swift 3 中将我的 textView.typingAttributes 前景色设置为红色。

textView.typingAttributes[NSForegroundColorAttributeName] = UIColor.red

现在,我已经迁移到 Swift 4,它的显示错误,我尝试如下,但它仍然显示错误。正确的设置方法是什么?

textView.typingAttributes[NSAttributedStringKey.foregroundColor] = UIColor.red

【问题讨论】:

    标签: ios uitextview nsattributedstring swift4 xcode9-beta


    【解决方案1】:

    试试这个:

    textView.typingAttributes[NSAttributedStringKey.foregroundColor.rawValue] =
        UIColor.red
    

    【讨论】:

      【解决方案2】:

      对于 Swift 4.2 和 Swift 5.0,它是

      textView.typingAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多