NSAttributedString superscript styling

后端 未结 4 549
南笙
南笙 2020-11-29 04:27

I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very go

4条回答
  •  [愿得一人]
    2020-11-29 05:14

    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

提交回复
热议问题