Reputation: 3026
I'm trying to create the following auto layout with interface builder:
At the top of the view:
Filling the rest of the space below the image view:
Can this be done solely in IB?
-Scott
Upvotes: 2
Views: 2854
Reputation: 119242
No it can't, because you can't express relationship constraints in interface builder.
You can do everything else (almost, see edit) except the height of the image view. You can set a constant height constraint on the view (perhaps set to the width of the iPhone screen) and then create an outlet to it.
At run time, if you're running on iPad (I assume the requirement is to work between iPad and iPhone rather that portrait and landscape, since your description doesn't make sense for landscape) then remove this constraint and add a new one pinning the height of the image view to be the same as its width.
Here's how to set up the rest of the constraints. I'm assuming you're starting with a view controller just containing its main view outlet.
You want it to look something like this:
For some reason, IB adds, and wouldn't let me remove, the height constraint on one of the buttons. It didn't seem happy to have the three buttons of equal height, and to derive the height of each one at runtime based on the spacing and the height of the image view. It may also be necessary to remove that constraint at runtime, or I may have missed something while bashing this together. Anyway, hopefully the principles outlined above are helpful.
Upvotes: 4
Reputation: 3152
To make the UIImageView
squared you would need to make the constraint trough code. I think all of the other requirements can be covered in IB, but personally, I would advise you to make it trough coding.
Good luck.
Upvotes: 0