NSAttributedString换行
来源:互联网 发布:js输出99乘法表 编辑:程序博客网 时间:2024/06/18 00:11
常用属性:
NSFontAttributeName 文字字体
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);
[段落样式demo]
1 UILabel * lable = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 200)]; 2 lable.backgroundColor = [UIColor lightGrayColor]; 3 lable.numberOfLines = 0; 4 [self.view addSubview:lable]; 5 6 NSString * string = @"Always believe that something wonderful is about \nto happen!"; 7 8 //富文本 9 NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:string];10 11 //段落样式12 NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];13 14 #warning lable.numberOfLines必须为0,段落样式才生效15 //行间距16 paragraphStyle.lineSpacing = 10.0;17 //段落间距18 paragraphStyle.paragraphSpacing = 20.0;19 20 // paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;21 // paragraphStyle.firstLineHeadIndent = 10.0;22 // paragraphStyle.headIndent = 50.0;23 // paragraphStyle.tailIndent = 200.0;24 25 [attributedString addAttribute:NSParagraphStyleAttributeName26 value:paragraphStyle27 range:NSMakeRange(0, string.length)];28 29 lable.attributedText = attributedString;
0 0
- NSAttributedString换行
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString
- NSAttributedString 详解
- NSAttributedString 详解
- 关于禁止ViewPager预加载问题,完美解决!
- Oracle 回收表空间文件空闲的空间
- 工作笔记---js和java共同完成大写锁定提示
- http://cmsblogs.com/?p=1530
- 认证授权和审计
- NSAttributedString换行
- JS定义类的六种方式详解
- C语言:变量定义
- Log4delphi使用心得
- rapidjson官方教程
- 关于机器学习中Precision和Recall的概念的理解
- Caffe扩展新层
- 2015年ACM长春赛区网络赛G题
- BA无标度网络模型构造算法