iOS lable内容格式的设置
2015-08-20 09:25
531 查看
一个label中设置的文本含有2种以上不同的格式,又不能把它拆解为两个label来显示,这时用NSMutableAttributedString可以很好的解决问题。
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: label.attributedText];
[text addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(10, 1)];
[label setAttributedText: text];
设置不同字体颜色
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
//设置字号
[str addAttribute:NSFontAttributeName value:font range:range];
//设置文字颜色
[str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
labell.attributedText = str;
}
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: label.attributedText];
[text addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(10, 1)];
[label setAttributedText: text];
设置不同字体颜色
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
//设置字号
[str addAttribute:NSFontAttributeName value:font range:range];
//设置文字颜色
[str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
labell.attributedText = str;
}
相关文章推荐
- 如何在多台机器上共享IOS证书
- 起学习iOS开发专用词汇
- iOS开发 - 二维码的生成与读取
- IOS博客
- iOS日历选取控件
- 从零开始学iOS开发的15条建议
- ios开发之控制器View的多种创建 -- 详解
- iOS中 @synthesize 和 @dynamic 区别
- iOS的电话号码344格式以及判断电话号码的正则表达式
- iOS Cell异步图片加载优化,缓存机制详解。
- OC_调用系统短信_邮件_电话
- 苹果开发者账号区别
- IOS动态类型isKindOfClass, isMemberOfClass
- iOS调试技巧
- 关于block的基本用法
- 创建自定义TextFile搜索框
- iOS动态彩条
- 神奇的IB_DESIGNABLE和IBInspectable
- 苹果开发 笔记(63)Masonry
- iOS项目开发实战——多个视图的平移动画与闭包函数的声明与调用