NSAttributedString换行

常用属性:

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;  //书写方式(NSWritingDirectionNaturalNSWritingDirectionLeftToRightNSWritingDirectionRightToLeft
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:NSParagraphStyleAttributeName 26 value:paragraphStyle 27 range:NSMakeRange(0, string.length)]; 28 29 lable.attributedText = attributedString;
技术分享
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值