我正在尝试创建一个子类UITableViewCell,我在右上角绘制一个图像.我有完美的工作 - 除非我设置self.backgroundView,我的背景图像掩盖了drawRect中绘制的图像.
必须有一种方法可以设置背景图像(和selectedBackgroundView),而不会掩盖drawRect中正在进行的操作.
我是以错误的方式来做这件事的吗?
编辑:我已经发布了一个问题示例项目.
- (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)];
}
Run Code Online (Sandbox Code Playgroud)
编辑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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个UITableViewCell,它覆盖了内容的完整绘图.我已经覆盖了正在调用的drawRect,但它仍然绘制了默认内容.
如何让它停止绘制默认内容,如何用自己的渲染替换它?
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
DLog (@"Overloaded TableCell initWithStyle");
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
DLog (@"TableCell::drawRect");
// expecting it to draw nothing
}
Run Code Online (Sandbox Code Playgroud)