iOS 富文本~设置字体大小和颜色
来源:互联网 发布:telnet测试端口问题 编辑:程序博客网 时间:2024/06/07 03:48
//联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄
一、富文本效果图:
图1:二、富文本实现代码:
//1.初始化UILabel
UILabel *introLabel = [UILabellableFrame:CGRectZerotitle:nilbackgroundColor:[UIColorclearColor]font:kGlobalFontSize_28textColor:[UIColorpurpleColor]];
//2.初始化富文本
NSMutableAttributedString *indroStr = [NSMutableAttributedStringsetupAttributeString:@"张琼在新神力酒店工作"rangeText:@"张琼"textColor:OKColorRGB(236,198, 128)];
introLabel.attributedText = indroStr;
introLabel.frame = CGRectMake(10,100,500,40);
[self addSubview:introLabel];
//注意:效果是@“张琼在新神力酒店上班”可以设置一个颜色,这字符串中的@“张琼”可以设置其它的颜色和字体大小.
三、富文本实现的分类方法
//分类
#pragma mark - 创建UILabel
+ (UILabel*)lableFrame:(CGRect)frame title:(NSString *)title backgroundColor:(UIColor*)color font:(UIFont*)font textColor:(UIColor*)textColor
{
UILabel *lable=[[UILabelalloc]initWithFrame:frame];
lable.text=title;
lable.font=font;
[lable setBackgroundColor:color];
lable.textColor=textColor;
return lable;
}
#pragma mark - 富文本设置部分字体颜色
+ (NSMutableAttributedString *)setupAttributeString:(NSString *)text rangeText:(NSString *)rangeText textColor:(UIColor *)color {
NSRange hightlightTextRange = [textrangeOfString:rangeText];
NSMutableAttributedString *attributeStr = [[NSMutableAttributedStringalloc] initWithString:text];
if (hightlightTextRange.length >0) {
[attributeStr addAttribute:NSForegroundColorAttributeName
value:color
range:hightlightTextRange];
[attributeStr addAttribute:NSFontAttributeNamevalue:[UIFontboldSystemFontOfSize:14.0f]range:hightlightTextRange];
return attributeStr;
}else {
return [rangeTextcopy];
}
}
谢谢!!!
- iOS 富文本~设置字体大小和颜色
- iOS 富文本~设置小数点后面字体大小和颜色
- iOS-[NSAttributedString]设置富文本和计算富文本高度
- ios富文本,一段文本两种字体大小,两种颜色
- ios 设置富文本
- ios富文本设置
- MFC设置文本字体大小颜色
- IOS中的富文本设置
- SpannableStringBuilder为文本设置不同字体大小,颜色
- iOS 设置uitextField的placehold的字体颜色和字体大小
- iOS 设置NavigationItem的Title的字体大小和颜色
- iOS 计算富文本高度和设置段落样式
- webStorm设置颜色和字体大小
- 富文本的使用之二 设置TextView不同字段的颜色和背景颜色
- iOS swift设置导航栏(navigationBar)背景颜色,标题颜色和字体大小,item颜色
- iOS 从一串文字中找到某个文字,设置某文字的颜色/富文本问题
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- eclipse安装反编译插件记录
- Idea 15 激活
- 18则幽默段子,让你秒懂经济和金融!
- esx 主机cli命令行简单介绍
- 数据挖掘模型中的IV和WOE详解
- iOS 富文本~设置字体大小和颜色
- 动态显示隐藏<td>标签或二级菜单
- 全排列递归算法
- Keepalived简介
- Kafka配置参数详解
- Anagram(回文构词法),哈希映射
- C语言(29)阶乘尾数零的个数
- 【Unity】unity3d NavMeshAgent 导航显示路径
- git 项目资料