私はこの次のコードを持っています:
@implementation MyImageView
@synthesize image; //image is a UIImage
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void) removeFromSuperview
{
self.image = nil;
[super removeFromSuperview];
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
if (self.image)
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
//the below 2 lines is to prove that the alpha channel of my UIImage is indeed drawn
//CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
//CGContextFillRect(context, rect);
CGContextDrawImage(context, self.bounds, self.image.CGImage);
}
}
@end
コードを実行すると、ビューの背景が黒であることがわかりました。私のUIImageに問題があるかどうかをテストするために、CGContextClearRect(context, rect)の後にコメントされた2行を使用しました。確かに白い背景が描かれていました。黒い背景を削除する方法はありますか? MyImageView を初期化するとき、既に backgroundColor を [UIColor clearColor] に設定しています。
どんなアドバイスでも大歓迎です。ありがとう