iOS Label line spacing

To adjust the line spacing of the label, you need to use the attributedText attribute of the label instead of the text attribute, as follows:

        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newString];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5; // 调整行间距
        NSRange range = NSMakeRange(0, [newString length]);
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
        self.detailLab.attributedText = attributedString;

 

Guess you like

Origin blog.csdn.net/bitcser/article/details/95595993