UILabel设置行间距

时间:2023-03-08 17:11:13

UILabel设置行间距:

            NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:contentLabel.text];

            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc]init];

            [paragraphStyle setLineSpacing:];

            [attributedString addAttribute:NSParagraphStyleAttributeNamevalue:paragraphStyle range:NSMakeRange(, contentLabel.text.length)];

            contentLabel.attributedText = attributedString;

            //调节高度
CGSize size = CGSizeMake(width, MAXFLOAT); CGSize labelSize = [contentLabel sizeThatFits:size];