美文网首页
金钱 富文本

金钱 富文本

作者: gxatios | 来源:发表于2018-01-16 11:17 被阅读9次

+(NSMutableAttributedString *)moneyFontGet:(NSString *)inputStr{
NSMutableAttributedString *resultStr = [[NSMutableAttributedString alloc] initWithString:inputStr];
if (inputStr.length == 0) {
}else{
NSString *frontStr;
NSString *endStr;
if ([inputStr containsString:@"."]) {
NSRange range = [inputStr rangeOfString:@"."];
frontStr = [inputStr substringFromIndex:range.location];
endStr = [inputStr substringToIndex:range.location];
NSMutableDictionary *frontDic = [NSMutableDictionary dictionary];
frontDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:16];
frontDic[NSForegroundColorAttributeName] =[ UIColor lightGrayColor];
[resultStr addAttributes:frontDic range:[inputStr rangeOfString:frontStr]];

        NSMutableDictionary *endDic = [NSMutableDictionary dictionary];
        endDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
        endDic[NSForegroundColorAttributeName] =[ UIColor blackColor];
        [resultStr addAttributes:endDic range:[inputStr rangeOfString:endStr]];
        
        NSString *money = @"¥";
        NSMutableAttributedString *moneyStr = [[NSMutableAttributedString alloc] initWithString:money];
        NSMutableDictionary *moneyDic = [NSMutableDictionary dictionary];
        moneyDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:16];
        moneyDic[NSForegroundColorAttributeName] =[ UIColor lightGrayColor];
        [moneyStr addAttributes:moneyDic range:[money rangeOfString:money]];
        [resultStr insertAttributedString:moneyStr atIndex:0];
     }else{
         
     }
}
return  resultStr;

}

相关文章

网友评论

      本文标题:金钱 富文本

      本文链接:https://www.haomeiwen.com/subject/ywcsoxtx.html