【问题标题】:UITextView: how to set the AttributedText with an empty String?UITextView:如何使用空字符串设置 AttributedText?
【发布时间】:2017-06-08 09:26:13
【问题描述】:

我有一个 UItextView,我在应用程序的开头设置了 AttributedText,因此使用的是空文本,因为用户还没有填写任何内容。问题是,使用空字符串,AttributedText 接缝不适用于我将输入的新文本。怎么办?

【问题讨论】:

    标签: uitextview iso


    【解决方案1】:

    据我所知,没有直接的解决方案。用 "" 设置 AttributedText 不起作用。

    但是您可以轻松解决:

    if let text = field.attributedText?.string {
       //normal way
    } else {
       field.font = ...
       field.fontColor = ...
       //sorry, no shadow and other nice tricks
    }
    

    当然,你可以在 textFieldDidChange 时实现对文本字段的委托并调整属性,但这在输入中文时效果不佳,因为字母可以由多个字符组成,所以我不能使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 2011-03-11
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多