您的位置:首页 > 其它

计算(字符串)的长度-以及高度动态改变size

2017-05-23 15:25 330 查看
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是有道理的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: