如何在iOS开发中简单控制文本的行间距与行高

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];paragraphStyle.lineSpacing = 10 - (label.font.lineHeight - label.font.pointSize);NSMutableDictionary *attributes = [NSMutableDictionary dictionary];[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];label.attributedText = [[NSAttributedString alloc] initWithString:label.text attributes:attributes];

计算label的行高小技巧

 CGSize attSizeL = [self.taskListModel.cmUnitName boundingRectWithSize:CGSizeMake(CGRectGetWidth(self.view.frame) - 28,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}context:nil].size;

      float  LlineN = attSizeL.height / 18.0;

详情请看这里引用此博文

你可能感兴趣的:(如何在iOS开发中简单控制文本的行间距与行高)