I am new to AutoLayout and struggling with it a bit. I have a UIImageView
which is part of an UIView. When the app is running on a 3.5 inch device, I want the UIImageView to resize according to the change of the screen size.
I am not sure how to achieve this. From what I have seen so far, you can only set a fixed width and height of the views, is it possible to make them dynamically resize ? In other words, how can the UIImageView
resize accordingly to the super view's height ?
Example
This code will size the UIImageView
according to its superview's width and height.
UIImageView *myImageView = [[UIImageView alloc] initWithImage:theImage];
[self.view addSubview:myImageView];
[myImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSArray *imageViewConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[myImageView]|" options:0 metrics:nil views:@{@"myImageView": myImageView}];
[self.view addConstraints:imageViewConstraints];
imageViewConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[myImageView]|" options:0 metrics:nil views:@{@"myImageView": myImageView}];
[self.view addConstraints:imageViewConstraints];
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