你如何使整个 UITableViewCell 成为自定义图像?我这样做是为了原型(prototype)设计,但我找不到从哪里开始。我基本上需要 3 个具有相同图像的 UITableViewCells - 所以它们都是可重复使用的单元格。
关于如何做到这一点的任何想法?谢谢。
最佳答案
我想你想要的是:backgroundView
UITableViewCell
的属性(property)
你可以这样做:
-(void) tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath;
{
static UIImage* bgImage = nil;
if (bgImage == nil) {
bgImage = [[UIImage imageNamed:@"myimage.png"] retain];
}
cell.backgroundView = [[[UIImageView alloc] initWithImage:bgImage] autorelease];
}
或直接使用:
((UIImageView*)cell.backgroundView).image = [UIImage imageNamed:@"customBackground"];
((UIImageView*)cell.selectedBackgroundView).image = [UIImage imageNamed:@"selectedBackground"];
关于iphone - 让 UIImageView 填满整个 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14318336/