When I subclass UITableViewCell
, I override the layoutSubviews
method, and use CGRects to place my subViews inside the contentView
of the cell, like so:
First, in your initWithFrame
method:
-(id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
//bgImageView is declared in the header as UIImageView *bgHeader;
bgImageView = [[UIImageView alloc] init];
bgImageView.image = [UIImage imageNamed:@"YourFileName.png"];
//add the subView to the cell
[self.contentView addSubview:bgImageView];
//be sure to release bgImageView in the dealloc method!
}
return self;
}
Then you Override layoutSubviews
, like so:
-(void)layoutSubviews {
[super layoutSubviews];
CGRect imageRectangle = CGRectMake(0.0f,0.0f,320.0f,44.0f); //cells are 44 px high
bgImageView.frame = imageRectangle;
}
Hope this works for you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…