Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing a UIImageView programmatically

I have tried several different solutions to this problem with no success.

I have a UIImageView (created on the Storyboard) that has multiple Gesture Recognizers on it. I have trying to resize this UIImageView based on screen size to take advantage of the 4 inch display.

It appears that since the Imageview was built using the storyboard, I can't change it programmatically???

My current code looks like this:

//determine screen size, set scoring button width based on device size.
CGFloat lCurrentHeight = self.view.bounds.size.height;
if (lCurrentHeight == 568.0) {
    CGRect _redHeadImageFrame = _redHeadImage.frame;
    _redHeadImageFrame.size.width = 220;
    [_redHeadImage setFrame:_redHeadImageFrame];
}

Any ideas??? Thanks.

like image 496
SteveM Avatar asked Oct 15 '25 13:10

SteveM


1 Answers

If you are using autolayout you have to change withConstraint of the image, because manual changing of the frame will not work in this case.

EDIT

You can create IBOutlet for the width constraint as you do it for other controls - just select constraint in IB and move it with right button to your header file. Than in code change constraint:

[self.imageWidthConstraint setConstant:100.0];
like image 53
Sergey Demchenko Avatar answered Oct 18 '25 05:10

Sergey Demchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!