I'm trying to get my label to look like so:
But using attributed string, I managed to get this result:
My code:
NSString *string = [NSString stringWithFormat:@"%0.2f",ask];
NSMutableAttributedString *buyString = [[NSMutableAttributedString alloc] initWithString:string];
[buyString addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:15.0]
range:NSMakeRange(2, buyString.length - 2)];
self.labelBuy.attributedText = buyString;
As you see, the numbers after the dot, stay below, and I would like to pop them to the top as the first example. Is there any way to set attributed string frame?
You have to use NSBaselineOffsetAttributedName
.
From the doc:
NSBaselineOffsetAttributeName
The value of this attribute is anNSNumber
object containing a floating point value indicating the character’s offset from the baseline, in points. The default value is 0.
Available in iOS 7.0 and later.
From your example:
[buyString addAttribute:NSBaselineOffsetAttributeName
value:@(10.0)
range:NSMakeRange(2, buyString.length - 2)];
You may have to change the value to fit your needs.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments