————例子代码在最后
NSMutableAttributedString 结合 NSMutableParagraphStyle
可以设置 :
- 行间距
2.段落间距
3.第一行头缩进
......
UILabel *dLabel = _desLab;
NSString *dLabelString = dLabel.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:dLabelString];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//行间距
[paragraphStyle setLineSpacing:5.0];
//段落间距
[paragraphStyle setParagraphSpacing:10.0];
//第一行头缩进
[paragraphStyle setFirstLineHeadIndent:15.0];
//头部缩进
//[paragraphStyle setHeadIndent:15.0];
//尾部缩进
//[paragraphStyle setTailIndent:250.0];
//最小行高
//[paragraphStyle setMinimumLineHeight:20.0];
//最大行高
//[paragraphStyle setMaximumLineHeight:20.0];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [dLabelString length])];
[dLabel setAttributedText:attributedString];
____ 上图代码
UILabel *textLab = [[UILabel alloc] init];
textLab.numberOfLines = 0;
textLab.frame = �Rect; // 宏
textLab.font = FontSize(15); // 宏
NSString *string = @"1、在电脑端用浏览器打开http://xnyjf.com/ \n2、在网站页面顶部点击\"登录\",登录新能源金服 \n3、进入我的账户,点击\"充值\" \n4、在充值页面选择\"网银充值\"";
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 25;
paragraphStyle.paragraphSpacing = 10;
[att addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
[att addAttribute:NSForegroundColorAttributeName value:Title_Color range:NSMakeRange(0, string.length)];
[att addAttribute:NSForegroundColorAttributeName value:Color_Blue_Prompt range:[string rangeOfString:@"http://xnyjf.com/"]];
[att addAttribute:NSForegroundColorAttributeName value:Color_Blue_Prompt range:[string rangeOfString:@"登录"]];
[att addAttribute:NSForegroundColorAttributeName value:Color_Blue_Prompt range:[string rangeOfString:@"充值"]];
[att addAttribute:NSForegroundColorAttributeName value:Color_Blue_Prompt range:[string rangeOfString:@"网银充值"]];
textLab.attributedText = att;
网友评论