0

I've placed a UIImageView within a UIView within a storyboard and sized it so that the UIImageView is the same size as its parent View.

However if I add constraints I am wondering why interface builder puts forward values of -16 for the horizontal spacing:

enter image description here

I don't understand why the horizontal spacing values are not 0 if the UIImageView is exactly the same width as the parent UIView.

If I add 4 constraints of 0 then IB gives an error:

enter image description here enter image description here

Why is IB expecting the UIImageView to have a width of 288 when within the storyboard scene it is the same width as the parent UIView which itself has a width of 320.

I obviously have some fundamental misunderstanding of constraints but this seems totally unintuitive - The UIView has a width of 320 in the storyboard, the UIImageView has a width of 320 in the storyboard. Why is IB expecting a width of 288 and where and why are these -16 values coming from?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • I think your problem is similar to [this one](http://stackoverflow.com/questions/18959118/add-spacing-constraint-to-superview-in-xcode-5) – Droppy Oct 14 '14 at 15:23

1 Answers1

0

You've set the image view to be the same width as its container view's margin.

There are two ways to fix this:

  1. Uncheck the box that says "relative to margins" in interface builder.
  2. In the view controller's viewDidLoad method, set self.view.layoutMargins = UIEdgeInsetsZero
bryanjclark
  • 6,247
  • 2
  • 35
  • 68