1

I am making a subclass of UITableView cell.

I have set the cell contentView, backgroundView, and selectedBackgroundView all to a single CGInsetRect (Of the 180.0 rowHeight set in the tableView). My first problem is when I try to assign the inset rect to the image view- the image gets pushed +-5 points to the right. So I've resorted to making the rect manually.

Then I set the text label size and color, but the specific attributes I assigned do not appear until I click the cell.

When I don't set the text label manually- the image pushes the textLabel offscreen, only showing one letter and an "..." ellipsis.

It seems that every modification I make causes something to break, and it seems like my code is competing with some automatic system. Its very frustrating and I don't know what to do or even how to debug this. Any tips on the gotchas of layoutSubviews in UITableViewCell with storyboards would be awesome, because I seem to be missing something critical.

My layoutSubviews

-(void) layoutSubviews
{
    [super layoutSubviews];

    const CGRect insetRect            = CGRectInset( self.bounds, 7, 4 );

    self.contentView.frame            = insetRect;
    self.backgroundView.frame         = insetRect;
    self.selectedBackgroundView.frame = insetRect;

    self.imageView.frame              = CGRectMake(0, 0, 306, 172);
    self.textLabel.frame = CGRectMake(0, 132, 306, 40);
    self.textLabel.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5];

    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1];
}
4

0 回答 0