/**
* 设置属性字体
*
* @param elementString 需要设置的文字
* @param i 后数第几个位置停止设置
*
* @return 设置好的文字
*/
- (NSMutableAttributedString *) attributedString:(NSString *)elementString lastTextIndex:(int) i
{
NSString * str = elementString;
NSMutableAttributedString * attr = [[NSMutableAttributedStringalloc] initWithString:str];
// 设置金额字体和颜色
[attr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15]range:NSMakeRange(0, str.length-i)];
// 设置单位字体和颜色
[attr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:11]range:NSMakeRange(str.length-i, i)];
[attr addAttribute:NSForegroundColorAttributeNamevalue:UIColorFromRGBValue(0x323232)range:NSMakeRange(str.length-i, i)];
return attr;
}
本文介绍了一种在 iOS 应用中使用 Objective-C 对 NSMutableAttributedString 进行设置的方法,包括如何为不同部分的文字设定字体大小及颜色。
369

被折叠的 条评论
为什么被折叠?



