NSAttributedString superscript styling

后端 未结 4 557
南笙
南笙 2020-11-29 04:27

I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very go

4条回答
  •  野性不改
    2020-11-29 05:15

    Swift version:

    let fnt = UIFont(name:"Helvetica", size:20.0)
    let attributedString = NSMutableAttributedString(string:"GGG®GGG", attributes:[NSFontAttributeName : fnt!])
    attributedString.setAttributes([NSFontAttributeName : fnt!.fontWithSize(10), NSBaselineOffsetAttributeName: 10], range: NSRange(location: 3, length: 1))
    

提交回复
热议问题