I have a custom UIView. So myView class extend UIView. In initWithFrame:(CGRect)frame method I set UIImageView for my UIView as a background image.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.bgImage = [[[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, frame.size.width , frame.size.height)] autorelease];
int stretchableCap = 20;
UIImage *bg = [UIImage imageNamed:@"myImage.png"];
UIImage *stretchIcon = [bg
stretchableImageWithLeftCapWidth:stretchableCap topCapHeight:0];
[self.bgImage setImage:stretchIcon];
}
return self;
}
So when I create my view everything is fine.
MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
But if I want to change my view size to bigger or smaller:
customView.frame = CGRectMake(10, 10, 50, 50)];
then I have the problem with my background image. Because it's size didn't changed. What to do ? Ho to change bg image size together with view frame ?