I have three views as subview as shown below with equal width & height constraint
If view B has no data then it should show as below
My try If iset B's width as zero then all views width will be zero.
How to get this?
Thank you
To add equal width constraint, you will need to select both views by command clicking on both of them. Then click on the pin menu and the previously grayed out Equal Width checkbox is now available. Click on that and click Add 1 Constraint.
Aspect ratio constraint is used to control the width and height of a view as per a aspect ratio that you set here. There are some standard presets such as 1:1 which means width will be equal to height. Similarly other presets calculates the dimensions based on a ratio.
Auto Layout is the preferred technology to define layouts for user interfaces on iOS and macOS. Its goal: To make it easy for you to create user interfaces that adapt automatically to different screen sizes and orientations.
What can you do is add a width constraint to it (middle one) and make is less than 2000 with priority(1000) greater than equal width(750)
Now make an outlet and the the constant of with constraint(<2000) to zero.
You can find the sample here.
Why I have set the 2000
is because this constraint is only needed to zero the width. It shouldn't affect the width if the width is non-zero. Now as the width are equally (middle view) and it should be less than 2000
thus the view displays equally on the screen. And when I set the width constraint to zero the width of the middle view becomes zero as it's priority is higher than the equal widths.
This code sets the width of middle view to zero.
- (IBAction)btnClick:(id)sender {
self.widthView2.constant = 0;
}
Output:
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