NSAttributedString superscript styling NSAttributedString superscript styling ios ios

NSAttributedString superscript styling


The following code seems to do the trick:

UIFont *fnt = [UIFont fontWithName:@"Helvetica" size:20.0];NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"GGG®GGG"                                                                                     attributes:@{NSFontAttributeName: [fnt fontWithSize:20]}];[attributedString setAttributes:@{NSFontAttributeName : [fnt fontWithSize:10]                                  , NSBaselineOffsetAttributeName : @10} range:NSMakeRange(3, 1)];

enter image description here


Swift version:

let fnt = UIFont(name:"Helvetica", size:20.0)let attributedString = NSMutableAttributedString(string:"GGG®GGG", attributes:[NSFontAttributeName : fnt!])attributedString.setAttributes([NSFontAttributeName : fnt!.fontWithSize(10), NSBaselineOffsetAttributeName: 10], range: NSRange(location: 3, length: 1))


Swift 5

    let fnt = UIFont(name:"Helvetica", size:20.0)    let attributedString = NSMutableAttributedString(string:"2.099", attributes:[NSAttributedString.Key.font : fnt!])    attributedString.setAttributes([NSAttributedString.Key.font : fnt!.withSize(10), NSAttributedString.Key.baselineOffset: 10], range: NSRange(location: 4, length: 1))