user387184
user387184

Reputation: 11053

How to create a table cell layout like this?

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
}

Upvotes: 0

Views: 90

Answers (1)

RyanJM
RyanJM

Reputation: 7068

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.

Upvotes: 1

Related Questions