NSAttributedString superscript styling

后端 未结 4 527
南笙
南笙 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:02

    Swift 4.2

    In my example I want to subscript one instance of infinity symbol so my label's title will look like this:

    let font = UIFont(name: "Helvetica", size: 14.0)
    
    let attributedString = NSMutableAttributedString(string: "Solids(ΔE∞)•G7®", attributes: [NSAttributedStringKey.font : font!])
    
    attributedString.setAttributes([NSAttributedStringKey.baselineOffset: -5], range: NSRange(location: 9, length: 1))
    
    solidsLbl.attributedText = attributedString
    

提交回复
热议问题