话不多说,直接贴代码
- (NSMutableAttributedString *)plainStringToAttributedUnits:(NSString *)string comment:(NSString *)commentStr haveSuperscrip:(NSString *) upDown;
{
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:string];
UIFont *font = [UIFont systemFontOfSize:48.0f];
UIFont *smallFont = [UIFont systemFontOfSize:18.0f];
[attString beginEditing];
[attString addAttribute:NSFontAttributeName value:(font) range:NSMakeRange(commentStr.length, string.length - commentStr.length)];
[attString addAttribute:NSFontAttributeName value:(smallFont) range:NSMakeRange( 0, commentStr.length)];
if (upDown.length>0) {//@"1" 上角标 @"-1" 下角标
[attString addAttribute:(NSString*)kCTSuperscriptAttributeName value:upDown range:NSMakeRange(string.length - 1, 1)];
}
[attString endEditing];
return attString;
}
网友评论