How to display superscript for third power / cube characters as a string in UILabel?

I am trying to find a solution for it and confuse how to display the third power / cube in UILabel. I tried to find the answer in a previously asked question, but none of them were helpful.

Questions I tried to get answers to:

how-to-show-superscript-for-registered-symbol

UILabel and superscript

If I need to use unichars, how can I use them for add-ons?

Thanks..

+4
source share
2 answers

You need to specify a unicode character for superscript three:

NSInteger number = 10; NSString *cubedSymbol = @"\u00B3"; NSString *tenCubed = [NSString stringWithFormat:@"%d%@",number,cubedSymbol]; 

Much more fun will be here

+18
source

Another solution would be to use the Core Text framework to draw an NSAttributedString with the kCTSuperscriptAttributeName attribute in the section of the string you want to make superscript. The result is more work, including a custom drawing and more, but more flexible than using Unicode characters.

Here is a blog post that I found with more information: http://iphonedevelopment.blogspot.com/2011/03/attributed-strings-in-ios.html

NSAttributedString on Mac OS X has many nice uses built into AppKit, but Apple hasn't made it easy to work with UIKit for iOS.

+1
source

Source: https://habr.com/ru/post/1384894/


All Articles