4

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.

Lucas Eduardo
  • 11,525
  • 5
  • 44
  • 49
SteveM
  • 347
  • 1
  • 5
  • 17

3 Answers3

3

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];
Sergey Demchenko
  • 2,924
  • 1
  • 24
  • 26
  • I am using auto layout. In IB there are two constraints on this image width, and align trailing edge (which is want I want to have change with the new frame). How do I use withConstraints when setting the new frame? thanks! – SteveM Sep 11 '13 at 13:21
0

yes you need to use like this,

CGFloat lCurrentHeight = [[UIScreen mainScreen] bounds].size.height; //it will give 568

CGFloat lCurrentHeight = self.view.bounds.size.height;//it will give 548,in your case that condition failed.
Balu
  • 8,470
  • 2
  • 24
  • 41
0

There's no difference in resizing UIViews created by code or by the storyboard. It's exactly the same: setting the frame of the view, as you are doing.

What might be happening:

  1. Your if condition it's never true. Have you checked with a breakpoint if the code inside it is even called? Maybe there's some error in the float direct comparation. See this. Also, see this for a better understanding on how to check if it's 4 inch display.

  2. If the setFrame: code is actually called, check if you are using auto-layout in your view. Maybe there's a constraint in the UIImageView. In this case, you should play with this constraint, in order to resize the view correctly..

Community
  • 1
  • 1
Lucas Eduardo
  • 11,525
  • 5
  • 44
  • 49