I'm working on an application for iOS in which I would like to place the fractional value 1/2 as a single character within an NSString for use in an UILabel, is this possible?
Asked
Active
Viewed 1,283 times
0
-
1Not really, I just want to know if there is a simple code that would display 1/2 in the space of a single character. No maths for it or anything, just I want to see 1/2 :) – Paul Reed Dec 09 '11 at 15:30
-
1As Paul states, this is not a duplicate of the above questions, he just wants to express the character of 1/2, so please don't vote to close this based on those. – Brad Larson Dec 09 '11 at 17:14
-
How has this been closed as an exact duplicate? - it has nothing to do with the 'possible duplicate' link! Perhaps I was just bad at expressing the question! – Paul Reed Dec 09 '11 at 21:09
2 Answers
2
Try setting the label's text property to the Unicode of 1/2:
label.text = [NSString stringWithFormat:@"%C",0x00bd];

Luiz Carlos Querino Filho
- 765
- 4
- 12
2
You can simply use Mac OS's built-in character viewer: http://docs.info.apple.com/article.html?path=Mac/10.6/en/8164.html
So you can just do label.text = @"½"

Cyrille
- 25,014
- 12
- 67
- 90
-
'Course it works. More often than not, the simplest solution is also the best: a raw string like this takes less time to be interpreted than, say, the `stringWithFormat` solution above, or any `sprintf`-like method. – Cyrille Dec 09 '11 at 22:53