1
votes

There is a custom UITableViewCell subclass with xib. all elements' constraints are set in IB enter image description here

Let's take a look at Test label (UILabel element). It has 3 constraints: enter image description here

The trailing space to superview(cell's content view) is set to 12.

The leading space to superview is set to 12

The top space to superview is set to 5

But when I build and run, the real distance between left simulator's margin and label's leading side is 20! As well for top space - it is more then expected 5px

enter image description here

If I give to label long name - it gets resized and trailing space is positioned correctly -exactly to 12px, as expected.

The same situation is with 2 images below test label. While theirs leading spaces are set to 12, in reality they are distanced on 20 px from content view's left margin.

What can be the reason of issue?

1
Is your table view have some leading constraint to superviewChristeena John
If you double click on the constraint to edit it, does it say something like "Superview.trailing Margin" ? If so, you can uncheck the "relative to margin" box in the pull down.rdelmar
double click on constraint just show it's properties on the right sidealex
@Christeena John yes, tableview has constraint to leading space to superview with 0.alex

1 Answers

4
votes

By default in iOS 8 there is an 8px padding for margins (A view's margin property is UIEdgeInset with 8px padding for all four sides). When you set 12px for leading constrain the margin's 8px padding also will be added to the constrain, thats why your leading constrain is 20px.

Uncheck the "Relative to Margin" option for the leading constrain to fix this issue.

enter image description here