How to dynamically set the height of a UITableView?

后端 未结 5 2165
独厮守ぢ
独厮守ぢ 2020-12-29 14:23

I have a tableview with different cell heights using the heightForRowAtIndexPath: method.

I would like to dynamically set the height of a UITable

5条回答
  •  攒了一身酷
    2020-12-29 14:48

    Hello You can get height of text with below code and set height according to it.

    CGFloat textViewWidth = CGRectGetWidth(textView.bounds);
    CGSize inset = CGSizeMake(5.0,5.0);
    CGSize stringSize = [myString sizeWithFont:textView.font constrainedToSize:CGSizeMake(textViewWidth-2*inset.width,1024) lineBreakMode:UILineBreakModeWordWrap];
    BOOL textOutOfFit = stringSize.height+2*inset.height>CGRectGetHeight(textView.bounds);
    

提交回复
热议问题