Make selected string of text view Bold, Italic, Underline like native “Notes” app of iOS

后端 未结 3 1907
北海茫月
北海茫月 2021-01-16 03:32

Is there any help to make selected string of text view Bold, Italic, Underline like native \"Notes\" app of iOS. Please give me helpful links. I am tired of searching for th

3条回答
  •  野的像风
    2021-01-16 03:56

    Take a look at NSAttributedString. You can use that to create strings that have mixed attributes at different ranges.

    In Objective-C, the mutable version, NSMutableAttributedString has methods like setAttributes(_:range:) that let you change the attributes of an attributed string in a specified range.

    So you'd initialize an NSMutableAttributedString starting from a normal String object, and then use setAttributes(_:range:) function to set different attributes like Bold, Italic, etc on a range of the string.

    (No, I don't have sample code handy.)

提交回复
热议问题