Reputation: 9994
I have a UIView in a UIViewController in Storyboard. There is a UIImageView inside it.
I want to increase the height of UIView programmatically:
CGRect frame = headerV.frame;
frame.size.height = 100;
headerV.frame = frame;
The problem is it also stretch the UIImageView. If I do not want to add the UIImage programmatically, how can I solve this problem?
Upvotes: 1
Views: 2107
Reputation: 9977
Option 1 - using resizing flags
A) Disable autoresizesSubviews on headerV.autoresizesSubviews = NO
.
or
B) Setup the correct autoresizingMask on your imageView. Do this:
imageView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin
,
if it should stick to the top (or smth. else - whatever setup you want)
Option B - autolayout
setup your autolayout correspondingly ,)
(PS: You can do all of this in interfaceBuilder or within the code.)
Upvotes: 0
Reputation: 1661
In your storyboard, click on the UIImageView, open the size inspector and be sure to disable stretching width and height (in autosizing). It should look like this :
Upvotes: 2
Reputation: 38728
If you don't want to stretch the image then set it's contentMode
imageView.contentMode = UIViewContentModeCenter;
Upvotes: 0