0

All I like to do is a to create a UITableViewCell with a layout having two elements only like this:

"Text that can have a flexible length 
with mutliple lines..."
"one fix line directly follwing the above text"

So Basically 1. Flexible text field with variable length where the complete text has to be seen wrapped in multiple lines if required 2. one line directly following

While I found heightForRowAtIndexPath it still does not help how to do the layout of the second field in here...

   -(void) layoutSubviews {
    [super layoutSubviews];
    [flexibleText setFrame:CGRectMake(  5.0,  5.0, 250.0, 40.0)];  //<- fexible height
        [one_line setFrame:CGRectMake(  5.0, 42.0, 250.0, 20.0)]; //<- followed by this one liner
}
user387184
  • 10,953
  • 12
  • 77
  • 147

1 Answers1

1

You'll have to subclass a UITableViewCell and then in the layout calculate how large the first label needs to be. Look at this What is -[NSString sizeWithFont:forWidth:lineBreakMode:] good for? for how to use -[NSString sizeWithFont:constrainedToSize:lineBreakMode:].

Then reposition your second label's frame based on the first.

You can then create a method that will return the needed height for the cell and call that in your heightForCell method.

Community
  • 1
  • 1
RyanJM
  • 7,028
  • 8
  • 60
  • 90
  • thanks very much for the hint. But the required logic for all this is really ridiculous: first the table asks for all the heights of each cell, then it starts to build each cell laying out the subviews AFTER I am supposed to know the complete height of the cell... So to actually compute the height of the cell one has to compute the height of the required text BEFORE it is laid out. But again, thank you very much for the hint which seems to be the only way to go. By the way in Android it's one statement: WRAP-CONTENT :-) – user387184 Mar 16 '13 at 19:06