1

I need to have 19th century in my UILabel. But it should appear as 19th century where the th symbol is a superscript. I am entering the label using plist. How do I ensure that it appears correctly in UI?

Need some guidance on this.

Image attached:enter image description here

lakshmen
  • 28,346
  • 66
  • 178
  • 276

2 Answers2

2

Use Unicode characters (U+1D57) and ʰ (U+02B0).

You can enter these literally as:

NSString *num = @"19 ᵗʰ";

or:

NSString *num = @"19\u1d57\u02b0";

If those don't look nice enough, using an NSAttributedString would be best.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • from plist file also the same? – lakshmen May 21 '13 at 06:59
  • 2
    In a plist you will want to use the first form with the actual characters typed in. The `\uxxxx` format only works in an `NSString` or `char` literal. – rmaddy May 21 '13 at 07:00
  • See how it looks on a real device when you run the app. The font you see in Xcode's plist editor and what you see on the device will be different. But it may not look all that great on the device either. See what you get. – rmaddy May 21 '13 at 07:23
  • this is what it looks in the plist editor: "late 19ᵗʰ century when". Both simulator and device, it looks out of size... I will attach an image. – lakshmen May 21 '13 at 07:26
  • It all depends on the font. The characters I suggested are only close approximations to what you really want. – rmaddy May 21 '13 at 07:27
  • how to type U+1D57 in mac? – lakshmen May 21 '13 at 07:34
  • Use the Character Viewer (Edit | Special Characters). – rmaddy May 21 '13 at 07:38
  • doesn't work using the unicode strings... How about the attributed strings? Do you have the solution for that? – lakshmen May 21 '13 at 08:43
  • You can't put an attributed string in a plist. But see the unaccepted answer at the following question for how to create an `NSAttributedString` in iOS that contains a superscript: http://stackoverflow.com/questions/5080175/how-to-create-subscript-characters-thats-not-in-unicode-in-ios – rmaddy May 21 '13 at 15:41
0

NSAttributedString has a property for that on osx, so perhaps it will be available on ios7. for now you could either store html in your plist and display that, or store 2 strings '19' and 'th' and manually add two uilabels into the top level one and manually layout them to create the superscript effect.

bazik
  • 609
  • 3
  • 18