Note that there are some explanatory texts on larger screens.

plurals
  1. POsubclassed UITableViewCell - backgroundView covers up anything I do in drawRect
    primarykey
    data
    text
    <p>I'm trying to make a subclassed UITableViewCell where I draw an image in the upper right corner. I have it working perfectly - except when I set self.backgroundView, my background image covers up the image drawn in drawRect.</p> <p>There must be a way to be able to set a background image (and the selectedBackgroundView) without covering up what's being done in drawRect.</p> <p>Am I going about this the wrong way?</p> <p>EDIT: I've posted an <a href="http://dl.dropbox.com/u/2349787/UIImage_Position_subclassed_cell.zip" rel="noreferrer">example project with the problem</a>.</p> <pre><code> - (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)]; } </code></pre> <hr> <p>EDIT 2: at AWrightIV's request, here's how I got it working... which didn't require subclassing UITableViewCell at all. I'm just adding a subview to cell.backgroundView:</p> <pre><code>// 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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload