iOS - UILabel设置行间距及文字居中

iOS - UILabel设置行间距及文字居中_第1张图片

// 调整行间距
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// 设置文字居中
paragraphStyle.alignment = NSTextAlignmentCenter;
[paragraphStyle setLineSpacing:12];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];
txt.attributedText = attributedString;

你可能感兴趣的:(iOS开发)