-
-
Save heliang219/5cafe45dfed03f1d0c70567ea656fae4 to your computer and use it in GitHub Desktop.
[计算UILabel中text的rect] 计算UILabel中text的rect #UILable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 过期的方法 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment