How to configure iOS UITextViews and UILabels so that their height is determined by their contents

I am basically trying to find the right way to create a UITableViewCell with two UITextViews and three UILabels inside it. Two UITextViews have dynamic content, and their size cannot be determined until runtime.

I tried various methods for recalculating the height of my UITextViews based on the content that loads into them at runtime, and although it is very time-consuming and crazy, I got it to work, but then they bleed for UILabels located in xib below them.

Do I really need to recalculate the y-coordinates of each UILabel after calculating the new size of the UITextViews? Is there a way to simply have elements in xib "push" the elements below them down depending on their new size?

What is the right approach to setting up a UITableViewCell with multiple dynamic text views so that my entire application does not consist of code for calculating heights and coordinates?

Or is it the answer that I should not put more than one dynamic UITextView in the same UITableViewCell?

+5
source share
3 answers

I used something like this for a cell to calculate its height in

tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

function

    CGSize labelSize = [self.comments sizeWithFont:[UIFont fontWithName:@"Verdana" size:17.0] 
                                                 constrainedToSize:CGSizeMake(280.0f, MAXFLOAT) 
                                                     lineBreakMode:UILineBreakModeWordWrap];
    return labelSize.height + 20;

+20 - to fill.

and also if you have every cell similar to the one you mentioned above, than you can create a UITableViewCell class with the following UIView elements inside it.

+2
source

iOS, , - - , . , , UITableViewCell, autoresizingMask UILabel UIViewAutoresizingFlexibleBottomMargin, UILabels . , UITableViewCell . , , - y- .

+1

It was convenient for me to add such behavior as a category in UIView, so the view can resize one of its subzones to fit arbitrary text, and, if necessary, resize the parent view to fit the new enlarged subview as necessary.

http://blog.carbonfive.com/2009/07/10/resizing-uilabel-to-fit-text/

0
source

All Articles