- (id)initWithFrame:(CGRect)frame {
UIImage* loadedImage = [UIImage imageNamed:@"balloonguy.png"];
CGRect rect = CGRectMake(0, 0, loadedImage.size.width, loadedImage.size.height);
self = [super initWithFrame:rect];
image=[loadedImage retain];
self.opaque = YES;
self.backgroundColor = [UIColor clearColor];
return self;
}
我将其添加为子视图,一切都很棒。
然而,我不能做的事情就是改变图像。我不会列出我失败的尝试,但做我做了什么?
答案 0 :(得分:1)
我认为您在更改image
属性时需要重新绘制视图,因此在这种情况下覆盖属性设置器可能是个好主意:
- (void) setImage:(UIImage *) im {
[image release];
image = nil;
image = [im retain];
[self setNeedsLayout];
}