I'm using autolayout with XIB a file to make the header view of a UITableView.

The construction is as follows:

-- UIView
--- Spacing View
---- Padding View
----- ImageView

What I would like to achieve is the following:
I would like to give the image view a fixed height ( fixed aspect ratio would be even better). And be able to increase the "space" between SpacingView and UIView, also the "padding" between SpacingView and PaddingView while still keeping the ImageView's height unchanged.

The idea is to be able to change the top and bottom constraints for space and padding independently. So I should be able to add for example:

  • 10 Spacing top or
  • 10 Spacing top and 10 Spacing bottom or,
  • 10 Spacing top and 10 Padding top
  • ... etc, you get the idea

I've tried tons of thing, changing the priorities, content hugging and compression of all/different view and constraints but after days of trying still no luck...

What seems the most logical to me would be for all views to have left, top, right, bottom constraints and the imageview a height constraint. And then when I want to change the space or padding, update the constant property of the corresponding constraint. But I think I might not understand autolayout very well because the console tells me it needs to break 7 constraints to achieve the correct result.

What am I missing here?

Related posts

Recent Viewed