Kumar Bibek
Kumar Bibek

Reputation: 9117

Autolayout a view to take up all space available

I am trying to setup a TableView (or any view) inside a View Controller using auto layout. I want the view to take up entire space available, for all configurations.

I have tried all sorts of things, tried searching for any solutions, but haven't found a straight forward way to achieve this.

Is this possible? If yes, can anyone help me by giving some pointers?

Adding more details:

Attached is a screenshot with a TableView embedded within a TabBar Controller item. I have 4 pins for all sides, with a distance 0, and priority 1000.

enter image description here

But, I can see orange lines, which looks like missing constraints. What am I missing?

Also, when i run this on an iPhone simulator, the table view doesn't render as I had wished. Here's a screenshot.

enter image description here

The table view doesn't extend to the sides, and the margins are also different.

Upvotes: 1

Views: 113

Answers (1)

Francesco Frascà
Francesco Frascà

Reputation: 186

In your storyboard, just select the TableView and add 4 pin constraints. One for all the edge to the parent view. Follow the picture below and ensure that the Constrain to margins is unchecked picture below

Then, if you are seeing same orange constraints, simply click on the third constraints button on the bottom right and select Update Frames like the next picturepicture

Try adding some DataSource to see the real results on simulator. The extra space on the right side will disappear if you put some data. The space on the left side, instead, is the default behavior.

Upvotes: 1

Related Questions