如何在UItableviewcell上添加比单元格本身和tableview更大的图像

时间:2013-06-11 15:07:00

标签: ios uitableview

如何将图像大于uitableviewcell本身作为子视图或背景视图。

我需要显示选择单元格时的背景图像。

修改: 文件附件见突出显示的行:箭头大于tableview本身,它大于单元格

2 个答案:

答案 0 :(得分:0)

在tableView数据源方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

你可以这样做:

UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_background.png"]];
cell.selectedBackgroundView = imageView;

选择单元格后,其背景设置为imageView

答案 1 :(得分:0)

如果您没有使用UITableViewCell的任何背景图片,请使用此delegate method of UITableView:`

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor redColor];
}

如果您使用UITableViewCell的背景图片,请使用cellForRowAtIndexPath:

中的背景图片
UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]];
cell.selectedBackgroundView = selBGView;