Here Before
Here Before

Reputation: 43

NSString format like html tag <sup>

How I can print on UILabel text like this "m³"?

Thanks

Upvotes: 0

Views: 699

Answers (4)

Rajesh
Rajesh

Reputation: 784

you can get the sup value by the unicode value 0x2081 or 0x2082 or 0x2083 means by changing last digit of 0x208

If you can print in uilabel m³ then follow the steps

const unichar ch = 0x2083; NSString *string = [[NSString alloc] initWithFormat:@"m%@", ch]; NSLog(@"%@",string);

It will print m³ what you want.

Then add the string value in UILabel.

Upvotes: 2

MrTJ
MrTJ

Reputation: 13192

For advanced formatting your best bet will be to use UIWebView:

UIWebView* webView;
// ...
NSString* html = @"m<sup>3</sup>";
[webView loadHTMLString:html baseURL:nil];

But if you want to use only ³ etc. probably it's simpler to use the unicode characters directly.

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726669

If superscripted digits is all you want, the easiest thing would be to use the superscripted digits from Unicode. You can put them in NSString, and use in UILabel without further modifications.

If you need more functionality, you can use NSAttributedString with OHAttributedLabel.

Upvotes: 1

He Shiming
He Shiming

Reputation: 5819

NSString and UILabel do not have such advanced formatting. You can print ³ though, because it's a character. Which you can safely put inside an NSString like NSString *symbol = @"³". To input other strings, click the U.S. flag at top right and choose Character Viewer.

Upvotes: 1

Related Questions