Superscripts in an attribute string
I am trying to get my shortcut to look like this:
But using the attributed string I was able 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 can see, the numbers after the dot remain below, and I would like to pull them out at the top as a first example. Is there a way to set an attributed inline frame?
source to share
You must use NSBaselineOffsetAttributedName
.
From the doc:
NSBaselineOffsetAttributeName
The value of this attribute isNSNumber
an object containing a floating point value that indicates the characters that are offset from the baseline, in points. The default is 0.
Available in iOS 7.0 and later.
In your example:
[buyString addAttribute:NSBaselineOffsetAttributeName
value:@(10.0)
range:NSMakeRange(2, buyString.length - 2)];
You may need to change the value to suit your needs.
source to share