UITextView with NSAttributedString and custom attributes not working

后端 未结 3 813
粉色の甜心
粉色の甜心 2021-02-08 23:25

When using a UITextView I try to add a custom attribute to an attributed string. However, all custom keys are lost after assigning to a UITextView\'s attributedText. Like this:<

3条回答
  •  死守一世寂寞
    2021-02-08 23:49

    Starting with iOS 7, it now works as you'd like:

    From Accessing Attributes:

    An attributed string identifies attributes by name, storing a value under the attribute name in an NSDictionary object, which is in turn associated with an NSRange that indicates the characters to which the dictionary’s attributes apply. You can assign any attribute name-value pair you wish to a range of characters, in addition to the standard attributes.

    It works with both standard and NSTextStorage (Text Kit) backed UITextViews.

提交回复
热议问题