I Have to divide a UIView
horizontally into three even sized subviews using Xcode
. I tried to use constraints.
I got the following result.
In some screen sizes. In small screen phones the leftmost and rightmost sub-views are same size. But, the center sub-view is very small in small screens and very large in big screens. So Please let me know the correct way to split the UIView
into three even sized sub-views horizontally. Thanks in advance.
Note: I'm using Xcode 8.1
Setting up constraint is technique that every used according to developer skills and usability. You will came with own one day. Here is the way i am using to handle situation like your.
1)Create 3 views with equal width on storyboard.(You have already Done that) 2)Select all 3 Views together .
Here is an image showing above step at once.
Now Select Last View ie. 3rd View (You must select only Last view)
You are good to go now.
Like i said earlier, go with your convenience.
First, hold "control" key and drag the view to its container view,
To set view's width equal to container view's width:
Second, change the multiplier value to 0.3333(means 1/3 width of container):
Next, set 2nd view's width equal to the 1st one:
Finally, add 3rd view and apply same set as 2nd one. And remember to add "Same Vertical Center to 1st View" constraint and "xx Leading Space" constraint for 2nd and 3rd view. You will get three same width views fill the container.
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