美文网首页
iOS 设置Label的行间距

iOS 设置Label的行间距

作者: 李炯7115 | 来源:发表于2017-11-13 17:08 被阅读24次

// 创建一个LabelUILabel*label = [[UILabelalloc] initWithFrame:CGRectMake(50,100,300,300)];// 设置为多行显示label.numberOfLines=0;

NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];// 行间距设置为30[paragraphStyle  setLineSpacing:15];NSString*testString = @"设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距";

NSMutableAttributedString  *setString = [[NSMutableAttributedString alloc] initWithString:testString];

[setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [testString length])];// 设置Label要显示的text[label  setAttributedText:setString];// 将创建的Label添加到view上[self.viewaddSubview:label];

学习链接:http://blog.csdn.net/u013892686/article/details/51324164

相关文章

网友评论

      本文标题:iOS 设置Label的行间距

      本文链接:https://www.haomeiwen.com/subject/xowzmxtx.html