lujop
lujop

Reputation: 13893

Simple row layout using Autolayout constraints

I've a simple layout that I know how to do it with a horizontal stackview. But for learning purpouses I want to know if it is posible to code using AutoLayout constraints.

The layout is simple, it's a rectangular row that contains an image and a label. The problem is that the label can have multiple lines and be bigger than the icon.

The desired layout is that image and label had to be centered in Y axis and the bigger height one have a margin of 8 points at top/bottom.

Layout[1] enter image description here

Upvotes: 0

Views: 52

Answers (3)

Dheeraj D
Dheeraj D

Reputation: 4451

First Write this in viewDidLoad

self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44.0;

Set numberOfLine property to 0 in StoryBoard

Set UIImageView Constrains like:

Fixed Height and Width and Vertical Center in Container.

Set UILable Constrains to HorozontalSpacing from UIImageView Trailing Top Bottom from SuperView i.e Cell.

Hope it will work...

Upvotes: 0

Munahil
Munahil

Reputation: 2419

Give a top and bottom margin constraint for image and label. Set high priority with relation Greater Than or Equal.

Upvotes: 0

clemens
clemens

Reputation: 17722

You should give the image and the label a margin constraint for both top and bottom. Use greater or equal as relation for these margin constraints.

Upvotes: 2

Related Questions