Ali
Ali

Reputation: 9994

Avoid Stretching UIImageView inside a UIView

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

Answers (4)

calimarkus
calimarkus

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

ksh
ksh

Reputation: 1904

Set autoresizesSubviews property of your UIView to NO.

Upvotes: 1

Ashbay
Ashbay

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 :

enter image description here

Upvotes: 2

Paul.s
Paul.s

Reputation: 38728

If you don't want to stretch the image then set it's contentMode

imageView.contentMode = UIViewContentModeCenter;

Upvotes: 0

Related Questions