-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
I needed to use superscript/subscript but MDHTMLLabel doesn't support it, so I implemented it and though it works, it doesn't for iOS9.x. Texts are not subscripted nor superscripted. I've reviewed the code but can't make it where the problem could be.
This is the code I'm using that I implemented, showing subscript only:
- (void)applySubscriptToText:(CFMutableAttributedStringRef)text
range:(NSRange)range {
/* Because Helvetica Neue doesn't handle subscript AND because CT added kCTSuperscriptAttributeName key until ios11, this code is commented out:
CFAttributedStringSetAttribute(text, CFRangeFromNSRange(range), kCTSuperscriptAttributeName, (__bridge CFTypeRef)(@-1));
*/
NSMutableAttributedString *attributedString = (__bridge NSMutableAttributedString *)(text);
UIFont *subScriptFont = [UIFont fontWithName:self.font.fontName size:self.font.pointSize * 0.6];
[attributedString addAttribute:NSFontAttributeName value:subScriptFont range:range];
[attributedString addAttribute:NSBaselineOffsetAttributeName value:@(-1.5) range:range];
}
If you use iOS11 you can use the commented code and discard the rest (or you can leave the code as is and it will work for iOS > 9.x), otherwise it only works for iOS > 9.x.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels