1

My app in xcode has a tableview with some product data. One of my products have a superscript e in its name. How can I use superscript characters in a string like: texte

I can get it to work with numbers: text\u2070 -> text0 or text\u2071 -> text1. But how to do this with other characters?

thx!

Daniel
  • 1,275
  • 1
  • 22
  • 31
  • 1
    Maybe this will help: http://stackoverflow.com/questions/5080175/how-to-create-subscript-characters-thats-not-in-unicode-in-ios – Jason May 09 '12 at 08:22
  • 1
    Use the link @JasonWang gave you. We run into exactly the same problem and we did like it said there, using a webview and html. There were no other solutions – BBog May 09 '12 at 08:45
  • It has some good info but I can't use something like a webview in a tableview. Is the only way to do this with a image? – Daniel May 09 '12 at 08:48

3 Answers3

2

tl;dr: NSString does not support concept of super/sub script. That's more or less a UI formatting concern.

One possible solution is to dynically add UILabels in code instead of interface builder. You can add a second UILabel with a smaller font size.

Jason
  • 4,232
  • 3
  • 23
  • 31
2

Add CoreText framework, import CoreText.h, and use UIlabel.attributedText - it has full support for NSAttributedString. Asked and answered repeatedly on SO already.

Adam
  • 32,900
  • 16
  • 126
  • 153
2

For SubScript use value for kCTSuperscriptAttributeName as @-1.

As per the document

@discussion Value must be a CFNumberRef. Default is int value 0. If supported by the specified font, a value of 1 enables superscripting and a value of -1 enables subscripting.

extern const CFStringRef kCTSuperscriptAttributeName CT_AVAILABLE(10_5, 3_2);

Example- [lblHeader setText:@“Headers [Alpha1 – text”];

        NSMutableAttributedString *headerSubscript = [[NSMutableAttributedString alloc]initWithAttributedString: lblHeader.attributedText];

        [headerSubscript addAttribute:(NSString *)kCTSuperscriptAttributeName value:@-1 range:NSMakeRange(14,1)];      

        [lblHeader setAttributedText:headerSubscript];
Bhushan
  • 175
  • 1
  • 9