Resizing UITextView in custom UITableViewCell
ios, objective-c, uitableview
Solution
You have to do this calculation in
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
method and also resize the cell height accordingly.
If you got it, it's okay. Or If you need the code sample, just ask again. I think you got it !
Updated
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITextView *tempTV = [[UITextView alloc] init];
[tempTV setText:@"your text"];
CGFloat width = self.tableView.frame.size.width - TEXT_ORIGIN_X - TEXT_END_X;
CGSize size = [tempTV sizeThatFits:CGSizeMake(width, MAX_HEIGHT)];
return (TEXT_ORIGIN_Y + size.height + TEXT_BOTTOM_SPACE);
}
Problem
I have a custom `UITableViewCell` and I'm trying to resize the `UITextView` inside it based on the content size. I'm on iOS7 and using Autolayout. I've tried using the following: ``` [cell.question setScrollEnabled:YES]; [cell.question sizeToFit]; [cell.question setScrollEnabled:NO]; ``` and ``` - (CGRect)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width { UITextView *calculationView = [[UITextView alloc] init]; [calculationView setAttributedText:text]; CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)]; CGRect finalFrame = CGRectMake(0, 0, width, size.height); return finalFrame; } ``` from different SO posts. I'm able to resize the frame. But the issue is I'm not able to see the change visibly. In the sense, when I log it, I can see the change. But the `UITextView` doesnt resize. I cant find any autolayout dependencies either. When I disabled AutoLayout, it seems to work. How do I do this, by enabling AutoLayout? Thanks. EDIT Here's my `UITextView` constraints