I have an UIImageView in the in the controller's view with a distance of 20% of the screen height from the top of the view. ie I want to set the 20 % of the screen height as the top Constraint of the UIImageView.
Can I implement this without adding a transparent view, which is how I do it now (by setting its height to be 20% of the screen Height), to the container view ?
You can do it in the IB/StoryBoard itself. Since you want the top vertical space between the image view and it's superview to be always 20% of the height of the superview, it is same as setting the image view's height to be 80% of it's superview's height and pinning the bottom of image view to the bottom of it's superview. Hence, you can eliminate that transparent view from being added.
Steps (I'm only considering vertical constraints here):
1. Drag a constraint from the bottom of the image view to the bottom of it's superview.
2. Drag an equal heights constraint from the image view to it's superview. Change the multiplier value of this constraint to 8:10 in the Size Inspector (Screenshot's attached below).
Set the top constraint of your UIImageView to bottom of the main view, with constant 0, multiplier 0.2 or 2:10
Reason: the coordinate of your main view bottom is equal to the height of it ( the top most view of the controller).
Edit: Step by Step
UIImageView to top of the main view (like you normally do).main view top to 2nd item if needed, and set it to main view bottom instead of top.0, multiplier 0.2 or 2:10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With