Here's a solution that clings a bit, but it exactly fits my requirements ... with one fatal flaw: when the cells are reused, a star angle appears when I don't want it.
http://dl.dropbox.com/u/2349787/UIImage_Position_subclassed_cell2.zip
I still use drawRect here, but only because self.starImage is null if you access it in the initWithStyle method. In addition, instead of adding a subview to self.contentView, I add it to self.backgroundView to prevent clicking the delete cell button. The angle of the star is positioned correctly in both portrait and landscape modes, and works fine in edit mode.
With the problem of reusing cells, although it's still not ... so maybe I'm trying to do it again without subclassing UITableViewCell.
I am open to any further suggestions. Thanks!
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { // Initialization code self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]] autorelease]; } return self; } - (void) drawRect:(CGRect)rect { UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width - self.starImage.size.width, 0, self.starImage.size.width, self.starImage.size.height)] autorelease]; imageView.image = self.starImage; imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [self.backgroundView addSubview:imageView]; }
Jim rhoades
source share