IOS NSMutableAttributedString 富文本的设置
来源:互联网 发布:php旅游网站文献 编辑:程序博客网 时间:2024/05/22 04:48
1.NSAttributedString的初始化方法有:
1. -initWithString:用String初始化,并没有Attributed信息。
2. -initWithAttributedString:用AttributedString去初始化。
3. -initWithString:Attributed:用string及attribute的dictionary来初始化。
具体AttributtedString属性的键值对如下:
NSString *const NSParagraphStyleAttributeName;//值为NSParagraphStyle,设置段落属性,默认值为[NSParagraphStyle defaultParagraphStyle]返回的值。
NSMutableParagraphStyle与NSParagraphStyle包括一下属性
alignment //对齐方式
firstLineHeadIndent //首行缩进
headIndent //缩进
tailIndent //尾部缩进
lineBreakMode //断行方式
maximumLineHeight //最大行高
minimumLineHeight //最低行高
lineSpacing //行距
paragraphSpacing //段距
paragraphSpacingBefore //段首空间
baseWritingDirection //句子方向
lineHeightMultiple //可变行高,乘因数。
hyphenationFactor //连字符属性
NSString *const NSForegroundColorAttributeName;//值为UIColor,字体颜色,默认为黑色。
NSString *const NSBackgroundColorAttributeName;//值为UIColor,字体背景色,默认没有。
NSString *const NSLigatureAttributeName;//值为整型NSNumber,连字属性,一般中文用不到,在英文中可能出现相邻字母连笔的情况。0为不连笔;1为默认连笔,也是默认值;2在ios 上不支持。
NSString *const NSKernAttributeName;//值为浮点数NSNumber,字距属性,默认值为0。
NSString *const NSStrikethroughStyleAttributeName;//值为整型NSNumber,可取值为
enum {
NSUnderlineStyleNone = 0×00,
NSUnderlineStyleSingle = 0×01,
};设置删除线。
NSString *const NSUnderlineStyleAttributeName;//同上。设置下划线。
NSString *const NSStrokeColorAttributeName;//值为UIColor,默认值为nil,设置的属性同ForegroundColor。
NSString *const NSStrokeWidthAttributeName;//值为浮点数NSNumber。设置比画的粗细。
NSString *const NSShadowAttributeName;//值为NSShadow,设置比画的阴影,默认值为nil。
NSString *const NSVerticalGlyphFormAttributeName;//值为整型NSNumber,0为水平排版的字,1为垂直排版的字。
下面是代码运行的主要例子:
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue &0xFF00) >>8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0] // 这个是颜色的宏定义
// 主要的代码
NSString *mStr = @"119当天支付就有奖品";
NSString *mStrHint = [NSString stringWithFormat:@"%@ 查看详情",mStr];
UILabel *mLableTitle = [selfaddLableText:CGRectMake(0, 18, Screen_width, 15) withLabText:[SinglecreatDataHandle].mStrPresentHintwithLabFont:[UIFontfontWithName:HeitiSCLight size:18] withTextColor:UIColorFromRGB(0xFF3587)];
mLableTitle.textAlignment = NSTextAlignmentCenter;
mLableTitle.userInteractionEnabled = YES;
[self addSubview:mLableTitle];
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:mStrHint];
// 设置一段话的字体是从0 ~ 整个字符串的长度 设置字体,也可以为某几个字设置字体
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:18.0]
range:NSMakeRange(0, mStrHint.length)];
// 设置一段话的字体是从0 ~ 整个字符串的长度 设置字体的颜色,也可以为某几个字设置字体的颜色
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:UIColorFromRGB(0x8D52FD)
range:NSMakeRange(mStrHint.length - 4 , 4)];
// 设置一段话的字体是从后4个字符串 设置字体有下划线,
[AttributedStr addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
range:NSMakeRange(mStrHint.length - 4 , 4)];
mLableTitle.attributedText = AttributedStr;
[self addSubview:mLableTitle];
运行结果:
- IOS NSMutableAttributedString 富文本的设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- ios富文本NSMutableAttributedString
- NSMutableAttributedString/NSAttributedString 富文本设置
- NSMutableAttributedString IOS中的富文本
- iOS NSMutableAttributedString 实现富文本
- iOS NSMutableAttributedString 实现富文本
- iOS 富文本NSMutableAttributedString整理
- NSMutableAttributedString富文本的实现
- 富文本的使用 NSMutableAttributedString
- 富文本的使用 NSMutableAttributedString
- IOS开发-NSMutableAttributedString 富文本的使用
- iOS使用NSMutableAttributedString实现富文本
- iOS使用NSMutableAttributedString实现富文本
- iOS——NSMutableAttributedString 实现富文本
- C#的事件机制效率问题
- [高可用性] 负载均衡,会话保持,session同步(转)
- mysql数据库的一半操作
- hdu1690(最短路floyd)
- 从一款已上线的MMO手游分析游戏地图的同步方案
- IOS NSMutableAttributedString 富文本的设置
- 数据结构-顺序线性表基本操作实现
- iOS 【UIKit-首尾式动画不足&动画嵌套设置方法】
- 按字母加载联系人的数
- Swift 2.0 变量、常量定义
- 1020:Encoding
- linux 下退出 telnet
- ajax爬虫来了~
- 无向图欧拉回路求法