4

I'm trying to find solution for it and confused how do I display third power/ cube in a UILabel. I tried to find answer in previously asked question but none of them were useful.

Questions i tried to get answers :

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

UILabel and superscript

If I have to use unichars how do I use them for Superscripts??

Thanks..

Community
  • 1
  • 1
rohan-patel
  • 5,772
  • 5
  • 45
  • 68

2 Answers2

18

You need to include the unicode symbol for a superscripted three:

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

Plenty more fun is to be had here

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • nice :)... The keep incrementing the number in "\u00B3" to get other number superscripts... For example, for squared, "\u00B2"... This was great !!! – jsetting32 Jul 08 '13 at 22:28
1

Another solution would be to use the Core Text framework to draw an NSAttributedString with the kCTSuperscriptAttributeName attribute on the section of the string you want to make superscript. This ends up being more work including custom drawing and things, but is more flexible than relying on unicode characters.

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

NSAttributedString on Mac OS X has lots of nice uses built into AppKit, but Apple hasn’t made it easy with UIKit for iOS.

DouglasHeriot
  • 1,674
  • 2
  • 13
  • 19
  • 1. You need to import CoreText/CoreText.h ---- 2. You need to add CoreText framework ---- 3. You need to know the value for the attribute (not listed in this answer). Not a good answer. – Adam Sep 16 '13 at 07:34