随手笔记 UIlabel 简单富文本
来源:互联网 发布:centos 6.7 升级内核 编辑:程序博客网 时间:2024/04/28 05:36
NSString *str1 =@"简介:";
NSString *str2 = introduction;
NSString *text = [NSStringstringWithFormat:@"%@%@",
str1,
introduction];
// If attributed text is supported (iOS6+)
if ([self.videoInfoLBrespondsToSelector:@selector(setAttributedText:)]) {
// Define general attributes for the entire text
NSDictionary *attribs = @{
NSForegroundColorAttributeName: self.videoInfoLB.textColor,
NSFontAttributeName: self.videoInfoLB.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedStringalloc] initWithString:text
attributes:attribs];
// Red text attributes
UIColor *redColor = [UIColorblackColor];
UIFont *font=[UIFontsystemFontOfSize:17];
NSRange redTextRange = [textrangeOfString:str1];// * Notice that usage of rangeOfString in this case may cause some bugs - I use it here only for demonstration
[attributedText setAttributes:@{NSForegroundColorAttributeName:redColor,NSFontAttributeName:font}
range:redTextRange];
// Green text attributes
UIColor *greenColor = [UIColorblackColor];
NSRange greenTextRange = [textrangeOfString:str2];// * Notice that usage of rangeOfString in this case may cause some bugs - I use it here only for demonstration
[attributedTextsetAttributes:@{NSForegroundColorAttributeName:greenColor}
range:greenTextRange];
// Purple and bold text attributes
self.videoInfoLB.attributedText = attributedText;
}
// If attributed text is NOT supported (iOS5-)
else {
self.videoInfoLB.text = text;
}
- 随手笔记 UIlabel 简单富文本
- UILabel 简单的富文本
- UILabel显示富文本
- iOS UILabel富文本
- UILabel展示html富文本
- IOS之UILabel富文本
- iOS7加载富文本(UILabel)
- NGUI UILabel 富文本格式说明
- UILabel设置富文本格式显示
- UILabel 富文本 显示文字和图片
- iOS开发之UILabel(富文本)
- iOS UILabel富文本自适应高度
- 富文本 简单样式
- ios简单富文本demolabel
- HTML5 简单富文本编辑器
- UILabel 添加下划线,改变字体颜色,NSMutableAttributedString实现富文本
- iOS UILabel 显示带有html标签的富文本内容
- iOS UIlabel怎么加载html字符串 富文本的用法
- SSH框架之Hibernate(1)——映射关系
- android activity 窗口化后 隐藏
- 直观的Xcode快捷键展示
- MyEclipse(2013) 出现从svn检出项目项目后source folder 以文件夹的方式组织的解决方法
- poj1160 Post Office
- 随手笔记 UIlabel 简单富文本
- 无题
- 启动和关闭ADB服务(adb start-server和adb kill-server)
- Velocity 资料
- UNICODE与UTF-8的转换详解
- SQL Server设置主键自增长列
- busybox 文件系统 etc目录,登陆 login,密码 password,shadow
- LeetCode OJ 之 Search in Rotated Sorted Array (有序数组翻转后的查找)
- MKMapView的使用