How to make subscripts and superscripts using NSAttributedString?

前端 未结 5 1308
情书的邮戳
情书的邮戳 2020-11-27 15:40

I need to make subscripts for chemistry formulas (H2O, Na^2+, etc)?

Is this possible to do with NSAttributedString, or is there an alternative/easier way to make sub

5条回答
  •  误落风尘
    2020-11-27 16:19

    you can also do the following if you want to make it a litle cleaner

    NSDictionary *attr = @{ NSFontAttributeName: smallfont, 
                            (NSString*)kCTSuperscriptAttributeName: @1 }
    
    NSRange fabricWeightRange = NSMakeRange(fabricWeight.location + 2, 1);                   
    [subKeyString setAttributes:attr range:fabricWeightRange];
    

提交回复
热议问题