NSAttributedString
使用这个类,必须先导入CoreText框架。
给UILabel设置attributedText了会导致给UILabel中text,font,textColor,shadowColor,shadowOffset,textAlignment,lineBreakMode这7个属性设置值时无效果。
这个框架的应用场景一般在图文混排和搜索功能中应用比较多。
需求怎么让搜索的字高亮了。友情提醒:别想歪了,这是之前给的外包项目,不是我特意找的。
- 实例代码
效果:
NSParagraphStyleAttributeName 段落样式
(字符串通过“\n”进行分段,此设置必须在lable.numberOfLines = 0时有效,value通过NSMutableParagraphStyle设置,它有以下属性)
1 @property(readwrite) CGFloat lineSpacing; //行间距
2 @property(readwrite) CGFloat paragraphSpacing; //段间距
3 @property(readwrite) NSTextAlignment alignment; //对齐方式
4 @property(readwrite) CGFloat firstLineHeadIndent; //首行缩紧
5 @property(readwrite) CGFloat headIndent; //除首行之外其他行缩进
6 @property(readwrite) CGFloat tailIndent; //每行容纳字符的宽度
7 @property(readwrite) NSLineBreakMode lineBreakMode; //换行方式
8 @property(readwrite) CGFloat minimumLineHeight; //最小行高
9 @property(readwrite) CGFloat maximumLineHeight; //最大行高
10 @property(readwrite) NSWritingDirection baseWritingDirection; //书写方式(NSWritingDirectionNatural,NSWritingDirectionLeftToRight,NSWritingDirectionRightToLeft)
11 @property(readwrite) CGFloat lineHeightMultiple;
12 @property(readwrite) CGFloat paragraphSpacingBefore;
13 @property(readwrite) float hyphenationFactor;
14 @property(readwrite,copy,NS_NONATOMIC_IOSONLY) NSArray *tabStops NS_AVAILABLE_IOS(7_0);
15 @property(readwrite,NS_NONATOMIC_IOSONLY) CGFloat defaultTabInterval NS_AVAILABLE_IOS(7_0);
最近才开始往github上放东西 在公司写的又不能放= = 大家姑且看看吧
github地址: https://github.com/FuThD