heliang219
12/6/2019 - 9:21 AM

[计算UILabel中text的rect] 计算UILabel中text的rect #UILable

[计算UILabel中text的rect] 计算UILabel中text的rect #UILable

   
   // 过期的方法
   CGSize titleSize = [self.evaluationModel.subjectInfoModel.stems sizeWithFont:KFont_Bold(18) constrainedToSize:CGSizeMake(kMainScreenWidth - LRMragin * 2, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
    
    //现在的方法
    CGRect rect = [self.lbl_en.text boundingRectWithSize:CGSizeMake(kMainScreenWidth - LRMragin * 2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: self.lbl_en.font} context:nil];
    
    // YYLable获取文本高度
    -(CGFloat)getMessageHeight:(NSString *)mess andLabel:(YYLabel *)lb{
    
    NSMutableAttributedString *introText = [[NSMutableAttributedString alloc] initWithString:mess];
    introText.yy_font = KFont_Bold(StemsFontSize);
    introText.yy_color = kColorText_Regular;
    introText.yy_lineSpacing = 5;
    
    lb.attributedText = introText;
    CGSize introSize = CGSizeMake(kMainScreenWidth - LRMragin * 2, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:introText];
    lb.textLayout = layout;
    CGFloat introHeight = layout.textBoundingSize.height;
    return introHeight;
}