How to show superscript for “®” registered symbol?

前端 未结 6 2296
时光说笑
时光说笑 2021-02-13 01:10

I\'ve a issue regarding showing registered symbol as superscript. I\'ve used unicode value \\u00AE, but it shows in same line. I\'d like to have it a bit top of remaining texts.

6条回答
  •  眼角桃花
    2021-02-13 01:50

    For a simple to use Swift solution, you might want to checkout HandyUIKit. After importing it into your project (e.g. via Carthage – see instructions in README) you can do something like this:

    import HandyUIKit
    
    "My company^{®}".superscripted(font: UIFont.systemFont(ofSize: 20, weight: .medium))
    

    This line will return an NSAttributedString which will look exactly like what you're looking for. Just assign it to a UILabels attributedText property and that's it!


    If you're looking for subscripting a text, simply use subscripted(font:) instead. It will recognize structures like CO_{2}. There's also superAndSubscripted(font:) if you want to combine both.

    See the docs for more information and additional examples.

提交回复
热议问题