1:计算字符串的长度:
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],};
CGSize textSize = [text boundingRectWithSize:CGSizeMake(KscreenWith, 35) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;2:计算字符串的高度:
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],};
CGSize textSize = [text boundingRectWithSize:CGSizeMake(KscreenWith-8, 35) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
CGFloat textHeight =MAX(textViewHeight, textSize.height+10);
self.textView .frame =CGRectMake(CGRectGetMaxX(self.titleLable.frame)+spacing, self.titleLable.frame.origin.y, textViewWid, textHeight);注意:这里减去8是有道理的。
本文介绍如何在iOS中使用Objective-C来计算文本的宽度和高度,包括设置字体大小、考虑屏幕宽度等因素。文中提供了具体的代码实现。
777

被折叠的 条评论
为什么被折叠?



