Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable height UIViews and labels

Ok so I'm not in a table cell at this point. (I've seen a lot of threads regarding the height of cells.)

I have a detail view with a title and description at the top of the view, followed by a tableView below it. If the description is going to vary in length, how do I get the tableView to adjust with it accordingly so it always starts directly below it?

I see apple doing this in the app store application. If you look at an application description (as if you were going to buy it), they have an application description, and wherever that ends a scrolling pane of screenshots follow. How do they do the varying height on the text description like that?

Are they doing this all programmatically or can I use the layout controls in IB to do the same thing?

like image 345
Bob Spryn Avatar asked Aug 18 '26 07:08

Bob Spryn


2 Answers

you need to add table view programmatically in your view and set its frame as per your detail view's size

1> get the current frame of the detailView 2> add it's height and than add tableview to your view

like

UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(initX , initY + DetailViewFrame.size.height, TableWidth, TableHeight) style:UITableViewStylePlain];
[view addSubView:table];
like image 105
Mihir Mehta Avatar answered Aug 20 '26 22:08

Mihir Mehta


The layout controls in IB change how a view is sized when its parent view resizes. In this case, (I assume) the label and table view are sibling views, so you need to do this programatically. Having sizes the label to fit, find the bottom of it (the origin's y location plus the label's height) and use that to guide where you place the table view. You would probably do this in -viewDidLoad or -viewWillAppear:, depending on when you have enough information to do the calculation.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!