2

I'm making a picture in a frame and then user can resize the frame size in runtime. For this purpose I've made a custom UIView in my main UIViewController and inside this UIView I've placed 2 UIImageView. In Document Outline Pane of xCode it's hierarchy is:


View
|--ImageView
|--ImageView

I'm using this line of code to change size of UIView under different conditions it'll resize accordingly:

self.imageObject.frame = CGRectMake(self.imageObject.frame.origin.x , 
                                    self.imageObject.frame.origin.y, 
                                    200, 
                                    200);

imageObject is my UIView. When I run it the size of the UIView changes but UIImageView size remains the same. I've also tried doing the same for my UIImageView but it didn't work.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
  • Try this. CGRect frameA=self.imageObject.frame; frameA=CGRectMake(self.imageObject.frame.origin.x ,self.imageObject.frame.origin.y, 200, 200); self.imageObject.frame = frameA; [self.imageObject.frame setClipsToBounds:YES]; CGRect frameB=CGRectMake(0 ,0, frameA.size.Width, frameA.size.Height); [imageView setFrame:frameB]; – NewStackUser Dec 22 '14 at 09:20

3 Answers3

6

You can also Try This :-

imageView.frame = CGRectMake(0,0,imageObject.frame.size.width, imageObject.frame.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.imageShw.contentMode = UIViewContentModeScaleAspectFit;
1

Try:

imageView.frame = CGRectMake(0,
                             0,
                             imageObject.frame.size.width, 
                             imageObject.frame.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | 
                             UIViewAutoresizingFlexibleWidth;
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Avi Tsadok
  • 1,843
  • 13
  • 19
1

First You can try,

self.imageObject.autoresizesSubviews = YES;

Otherwise to get the subviews to resize, you can add autoresizing mask to the subviews, to the two imageviews in your case:

imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin   |
                             UIViewAutoresizingFlexibleRightMargin  |
                             UIViewAutoresizingFlexibleTopMargin    |
                             UIViewAutoresizingFlexibleBottomMargin |
                             UIViewAutoresizingFlexibleWidth        |
                             UIViewAutoresizingFlexibleHeight;

Check UIView documentation for more details.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
christijk
  • 1,753
  • 18
  • 26
  • I've set the autoresizesSubviews to YES but this didn't work. Doesn't autoresizingMask set the BOOL automatically to YES? – Alex Cio May 22 '15 at 09:42