I am working on the app in which I have to show fraction number on label.
NSMutableAttributedString * hogan = [[NSMutableAttributedString alloc] initWithString:self.toValue];
[hogan setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"DINPro-Bold" size:11.0]} range:NSMakeRange(9,6)];
UILabel *fal = [[UILabel alloc] initWithFrame:CGRectMake(100,12, 150.0, 50)];
fal.text = @"";
fal.textColor = [UIColor whiteColor];
fal.backgroundColor = [UIColor redColor];
fal.font = [UIFont fontWithName:@"DINPro-Bold" size:18.0];
fal.attributedText=hogan;
[self addSubview:fal];
and the Output of this code is 1/5. I want to show like this ⅕.
I have tried with attribute string but it doesn't work.
Can anyone please help me.
Thanks in advance.
I have created the following two helper functions which will return the unicode string for a given number (0-9) in subscript or superscript format:
Once you have these declared, you can easily call something like this:
Which would output the following:
⁵/₆
And even a screenshot for ya from my normal
UILabel
:EDIT
Here's a function that will work with any fraction, including
37/100
, for example:Calling the following:
Logs
³⁷/₁₀₀
.