Replace substring of NSAttributedString with another NSAttributedString

前端 未结 9 1147
野趣味
野趣味 2020-12-01 08:51

I want to replace a substring (e.g. @\"replace\") of an NSAttributedString with another NSAttributedString.

I am looking for a

9条回答
  •  执念已碎
    2020-12-01 09:26

    1. Convert your attributed string into an instance of NSMutableAttributedString.

    2. The mutable attributed string has a mutableString property. According to the documentation:

      "The receiver tracks changes to this string and keeps its attribute mappings up to date."

      So you can use the resulting mutable string to execute the replacement with replaceOccurrencesOfString:withString:options:range:.

提交回复
热议问题