解决UILabel设置富文本字体后(即设置行间距),文字没有居中显示
label.textAlignment = NSTextAlignmentCenter; //只设置这句是无效的
NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//关键代码
paragraphStyle.alignment = NSTextAlignmentCenter;
[paragraphStyle setLineSpacing:5];//设置距离
[attriString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [text length])];
label.attributedText = attriString;
网友评论