设置字符串中的数字的颜色和字体

2015-10-19 0 287
设置字符串中的数字的颜色和字体
+(void)setRichNumberWithLabel:(UILabel*)label Color:(UIColor *) color FontSize:(CGFloat)size
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:label.text];
    NSString *temp = nil;
    for(int i =0; i < [attributedString length]; i++)
    {
        temp = [label.text substringWithRange:NSMakeRange(i, 1)];
        if( [self isInt:temp]  ){
            [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                             color, NSForegroundColorAttributeName,
                                             [UIFont systemFontOfSize:size],NSFontAttributeName, nil]
                                      range:NSMakeRange(i, 1)];
        }
    }
    
    label.attributedText = attributedString;
}

遇见资源网 objective-c 设置字符串中的数字的颜色和字体 http://www.ox520.com/18072.html

上一篇: 计算时间差
下一篇: IOS自定义ComboBox
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务