如何在iOS 7中计算UITableViewCell中带有UITextView的高度?
我在类似的问题上找到了很多答案,但是每个解决方案都涉及到sizeWithFont:
方法,而这个方法已经被弃用了!
我知道我必须使用- (CGFloat)tableView:heightForRowAtIndexPath:
方法,但是如何计算我的TextView需要显示整个文本的高度呢?
如何在iOS 7中计算UITableViewCell中带有UITextView的高度?
我在类似的问题上找到了很多答案,但是每个解决方案都涉及到sizeWithFont:
方法,而这个方法已经被弃用了!
我知道我必须使用- (CGFloat)tableView:heightForRowAtIndexPath:
方法,但是如何计算我的TextView需要显示整个文本的高度呢?
UITextView *txtDescLandscape=[[UITextView alloc] initWithFrame:CGRectMake(2,20,310,2)];
txtDescLandscape.editable =NO;
txtDescLandscape.textAlignment =UITextAlignmentLeft;
[txtDescLandscape setFont:[UIFont fontWithName:@"ArialMT" size:15]];
txtDescLandscape.text =[objImage valueForKey:@"imgdescription"];
txtDescLandscape.text =[txtDescLandscape.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[txtDescLandscape sizeToFit];
[headerView addSubview:txtDescLandscape];
CGRect txtViewlandscpframe = txtDescLandscape.frame;
txtViewlandscpframe.size.height = txtDescLandscape.contentSize.height;
txtDescLandscape.frame = txtViewlandscpframe;
对于 iOS 8 及以上版本,您可以直接使用
your_tablview.estimatedrowheight= minheight
,您想要的最小高度
your_tableview.rowheight=UItableviewautomaticDimension