右上隅に画像を描画するサブクラス化されたUITableViewCellを作成しようとしています。self.backgroundViewを設定した場合を除いて、完全に機能しています。背景画像は、drawRectで描画された画像を覆っています。
drawRectで行われていることを隠さずに、背景画像(およびselectedBackgroundView)を設定できる方法が必要です。
私はこれを間違った方法で行っていますか?
編集:問題のあるサンプルプロジェクトを投稿しました。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// TODO: figure out why this covers up self.starImage that's drawn in drawRect
self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]] autorelease];
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self.starImage drawAtPoint:CGPointMake(self.bounds.size.width - self.starImage.size.width, 0.0)];
}
編集2:AWrightIVの要求で、これが私がそれを機能させる方法です...これはUITableViewCellのサブクラス化をまったく必要としませんでした。cell.backgroundViewにサブビューを追加しているだけです。
// create a UIImageView that contains the background image for the cell
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]];
// create another UIImageView that contains the corner image
UIImage *starRedImage = [UIImage imageNamed:@"starcorner_red.png"];
UIImageView *starImageView = [[UIImageView alloc] initWithFrame:CGRectMake(297,
0,
starRedImage.size.width,
starRedImage.size.height)];
starImageView.image = starRedImage;
// add the corner UIImageView as a subview to the background UIImageView
[bgImageView addSubview:starImageView];
// set cell.background to use the background UIImageView
cell.backgroundView = bgImageView;