Reputation: 4410
I wanna create a simple iOS application using autolayout that displays three UIViews. One on the top, one on the left and the other on the right. The top view should be 50 pixels high and fills the horizontal space completely. The left column should fill 40% of the horizontal space and should fill 100% of the vertical space. The right column should be 60% of the horizontal space and 100% of the vertical space. Finally in the left UIView wanna add a single button.
Upvotes: 0
Views: 2821
Reputation: 387
The two existing answers didn't work for me. My answer was built using Xcode version 10.1 (10B61).
The core question is "How Can I Set a View’s Width to be a Percentage in a Storyboard". Answer: the view's width needs to be associated with the superview.
Explanation:
Upvotes: 4
Reputation: 27448
Your constraints should be like,
first view - top,leading(left),trailing(right) and fix height
left view - top, left(leading), bottom and equal width with superview with multiplier 0.4 (or width constraint with 0.4 multiplier)
right view - top,right(trailing),bottom and equal width with superview with multiplier 0.6 (or width constraint with 0.6 multiplier)
hope this will help :)
Upvotes: 2
Reputation: 334
Yes, You can.
Upvotes: 6