设置标签中字符串的子串(指定位置)的颜色
2014-11-12 09:55
316 查看
设置标签中字符串的子串(指定位置)的颜色
/**
* @brief
函数作用: 设置指定位置字符串的颜色
*
* @param
参数解释:
colorName 字符串颜色
colorLoc 字符串颜色下标
colorLength 颜色长度
labelTitle 字符串名称
*
* @return
函数返回值:无
*/
- (void)setColorName:(UIColor*)colorName colorLoc:(NSUInteger)loc colorLength:(NSUInteger)len
labelTitle:(NSString*)title
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString
alloc]
initWithString:title];
[attributedString addAttribute:NSForegroundColorAttributeName
value:colorName
range:NSMakeRange(loc, len)];
self.font = [UIFont
fontWithName:@"Avenir-Light"
size:28];
self.textAlignment =
NSTextAlignmentCenter;
self.attributedText = attributedString;
[self
sizeToFit];
}
/**
* @brief
函数作用: 设置指定位置字符串的颜色
*
* @param
参数解释:
colorName 字符串颜色
colorLoc 字符串颜色下标
colorLength 颜色长度
labelTitle 字符串名称
*
* @return
函数返回值:无
*/
- (void)setColorName:(UIColor*)colorName colorLoc:(NSUInteger)loc colorLength:(NSUInteger)len
labelTitle:(NSString*)title
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString
alloc]
initWithString:title];
[attributedString addAttribute:NSForegroundColorAttributeName
value:colorName
range:NSMakeRange(loc, len)];
self.font = [UIFont
fontWithName:@"Avenir-Light"
size:28];
self.textAlignment =
NSTextAlignmentCenter;
self.attributedText = attributedString;
[self
sizeToFit];
}
相关文章推荐
- iOS设置字符串指定位置的颜色和字体
- 获取字符串中某个指定的子串出现的开始位置(CHARINDEX用法)
- 修改字符串中一段的颜色——字符串改变指定位置的颜色
- WinAPI: SetPixel 和 SetPixelV - 设置设备环境中指定位置的颜色
- android textview字符串指定分段设置字体颜色
- RichTextBox用法——设置指定字符串的颜色
- TextView设置指定位置处文字颜色的坑
- TextView中设置指定位置字符颜色
- C语言版字符串中获得子串的函数,获取字符串中指定位置的子串
- EditText的换行输入、输入起始位置、调用指定格式的系统键盘(显示和隐藏),光标颜色,密码动态设置可见性
- c# RichTextBox用法——设置指定字符串的颜色
- iOS开发:字符串设置指定内容的文字颜色、文字大小、文字字体类型
- 查找字符串中指定的子串的首次出现的位置
- Oracle EBS - SQL&PL/SQL: 取字符串中某个指定字符最后出现的位置到字符串结尾的子串
- RichEditControl用法——设置指定字符串的字体颜色
- 更新字符串列表中,指定位置的字符串
- 《汇编语言》读书笔记(7)——在屏幕的指定位置显示字符串
- 更新字符串列表中,指定位置的字符串
- 更新字符串列表中,指定位置的字符串
- WinAPI: GetPixel - 获取设备环境中指定位置的颜色