Attributed text, replace a specific font by another using swift

前端 未结 2 1502
慢半拍i
慢半拍i 2021-01-16 16:25

I\'m using attributed text in a UITextView. The text contain many fonts.

I\'m looking for a way to replace a particular font by another one.

Any swift approa

2条回答
  •  天命终不由人
    2021-01-16 17:06

    There is a method called attributesAtIndex(_:effectiveRange:). This method returns a dictionary that you can get the font from.

    You will need to iterate over each index to store the fonts. It will be slow, because in text files the font could potentially change every character. So I would recommend doing this off the main thread.

提交回复
热议问题