doesn't work for UITextFields or UITextView
I could have confirmed it did not work for UITextView, but worked for UITextField, in iPad simulator 13.4.
the developer documentation for NSAttributedStrings includes an NSAttributedStringKey named NSSuperscriptAttributeName
The constant NSSuperscriptAttributeName is only available in macOS, but I do not know why.
If Apple were planning to drop support for subscrip/superscript feature in iOS, it should not work for UILabel nor UITextField.
As far as tried, UITextView in iPad simulator can show attributedString made from HTML:
NSString *htmlString = @"X<sup>2</sup>";
attStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil error:nil];
NSLog(@"%@(%@)", attStr, kCTSuperscriptAttributeName);
self.textView.attributedText = attStr;
And `attStr` is shown as:
X{
NSColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSFont = "<UICTFont: 0x7fa49b40b330> font-family: \"Times New Roman\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSKern = 0;
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
NSStrokeColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSStrokeWidth = 0;
}2{
NSColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSFont = "<UICTFont: 0x7fa49b40c400> font-family: \"Times New Roman\"; font-weight: normal; font-style: normal; font-size: 10.00pt";
NSKern = 0;
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
NSStrokeColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSStrokeWidth = 0;
NSSuperScript = 1;
}
You can find `NSSuperScript = 1;`, where `NSSuperScript` is a raw string and not symbolized.
I tried this:
attStr = [[NSMutableAttributedString alloc] initWithString:@"X2"];
[attStr addAttribute:@"NSSuperScript" value:@1 range:NSMakeRange(1, 1)];
self.textView.attributedText = attStr;
And worked as expected.
As you know, using raw string for attribute names is not recommended and I do not know why constant symbol for NSSuperScript is not defined in iOS. But UITextView seems to have functionality to support superscript/subscript.
You should better send a bug report to Apple.