【发布时间】:2012-03-09 09:08:14
【问题描述】:
我有一个自定义 UIView。所以 myView 类扩展了 UIView。在 initWithFrame:(CGRect)frame 方法中,我将 UIView 的 UIImageView 设置为背景图像。
- (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;
}
所以当我创建我的视图时,一切都很好。
MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
但如果我想将视图大小更改为更大或更小:
customView.frame = CGRectMake(10, 10, 50, 50)];
那么我的背景图片有问题。因为它的大小没有改变。该怎么办 ?何与视图框架一起改变背景图像大小?
【问题讨论】:
标签: iphone uiview uiimageview