UILabel 自适应高度以及间距放大

//自适应高度
CGRect rect = [self.textLabel.text boundingRectWithSize:CGSizeMake(SCREENWIDTH - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: self.textLabel.font} context:nil];
self.textLabel.frame = CGRectMake(5, 5, SCREENWIDTH - 20, rect.size.height);

        //使text的间距放大
        NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.textLabel.text];
        NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle1 setLineSpacing:7];
        [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [self.textLabel.text length])];
        [self.textLabel setAttributedText:attributedString1];
        [self.textLabel sizeToFit];

你可能感兴趣的:(UILabel 自适应高度以及间距放大)