改变Lable部分颜色,大小
来源:互联网 发布:程序员机械键盘推荐 编辑:程序博客网 时间:2024/06/05 19:40
// 设置某段字的颜色
- (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTForegroundColorAttributeName
value:(id)color.CGColor
range:NSMakeRange(location, length)];
}
// 设置某段字的字体
- (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTFontAttributeName
value:(id)CFBridgingRelease(CTFontCreateWithName((CFStringRef)font.fontName,
font.pointSize*2,
NULL))
range:NSMakeRange(location, length)];
}
// 设置某段字的风格
- (void)setStyle:(CTUnderlineStyle)style fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTUnderlineStyleAttributeName
value:(id)[NSNumber numberWithInt:style]
range:NSMakeRange(location, length)];
- (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTForegroundColorAttributeName
value:(id)color.CGColor
range:NSMakeRange(location, length)];
}
// 设置某段字的字体
- (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTFontAttributeName
value:(id)CFBridgingRelease(CTFontCreateWithName((CFStringRef)font.fontName,
font.pointSize*2,
NULL))
range:NSMakeRange(location, length)];
}
// 设置某段字的风格
- (void)setStyle:(CTUnderlineStyle)style fromIndex:(NSInteger)location length:(NSInteger)length{
if (location < 0||location>self.text.length-1||length+location>self.text.length) {
return;
}
[_attString addAttribute:(NSString *)kCTUnderlineStyleAttributeName
value:(id)[NSNumber numberWithInt:style]
range:NSMakeRange(location, length)];
}
//其他方法
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
attrLabel.attributedText = str;
0 0
- 改变Lable部分颜色,大小
- lable大小固定,内容根据lable大小而改变
- ios tableview 根据文本改变lable大小
- TextView改变部分字体的大小和颜色
- 改变TextView部分字体的大小和颜色
- android TextView改变部分字体的颜色,大小,设置部分字体有点击事件
- 可变字符串改变颜色大小
- 代码改变字体颜色/大小
- 改变div大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- TextView改变部分字体的大小和颜色及首行缩进
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- tableView滑动删除返回错
- 内存不足的紧急处理方法
- div+css兼容ie6_ie7_ie8_ie9_ie10和FireFox_Chrome等浏览器方法
- 第十六周OJ题目
- 第16周项目--OJ平台相同的数字
- 改变Lable部分颜色,大小
- 设置Win7系统睡眠模式
- 统计学生成绩
- 第16周项目4-为动态数组扩容
- 嵌入式Linux USB WIFI驱动的移植
- Javascript的例外处理的一个实例
- 根据area分析省市
- android应用开发框架: KJFrameForAndroid
- 分类模型的性能评估——以SAS Logistic回归为例(2): ROC和AUC