I am not able to handle the subview resizing correctly:
Suppose I have a custom UIView class, inside it contains a UIImageView.
Initially, I set up the UIViews like the followings:
// width and height are UIImage width height
// it is possible that the UIImage width height is larger than the container
self.imageView.frame = CGRectMake(0 ,0, width, height)
self.imageView.backgroundColor = UIColor.redColor()
self.imageView.contentMode = UIViewContentMode.ScaleAspectFit
self.imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight,.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleBottomMargin]
addSubview(self.imageView)
self.frame = CGRectMake(0, 0, width, height)
self.backgroundColor = UIColor.greenColor()
Let's call this custom UIView as MyView.
And then when I want to place this "myView" in a ViewController. I did the followings:
myView.frame = CGRectMake(xPos, yPos, 100, 100)
myView.autoResizeSubviews = true
And I found that after I did this, I got the following results. MyView place at the correct place with correct size, but the internal UIImageView got even a smaller size.
Why that happen? And how to make all the subviews inside MyView resize correctly according to the frame of MyView?
Thanks.