在我的表格视图中,我需要将单元格分隔符设置为我随身携带的图像。我怎么能这样做?
答案 0 :(得分:8)
一个简单的解决方案是您可以将图案图像设置为单元格分隔符。
[tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:...]]];
或者您只需在单元格内容视图中添加UIImageView
即可UIImageView *imagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater.png"]];
imgView.frame = CGRectMake(0,cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1);
[customCell.contentView addSubview:imageView];
答案 1 :(得分:1)
您最好的选择可能是将表格的separatorStyle设置为UITableViewCellSeparatorStyleNone。
并在需要时手动添加/绘制一条线(可能在tableView:cellForRowAtIndexPath :)。
在tableView:cellForRowAtIndexPath:
...
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
separatorLine.tag = 4;
[cell.contentView addSubview:separatorLine];
[separatorLine release];
}
//设置默认单元格设置。
...
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
...
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
... 在viewDidLoad中:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
答案 2 :(得分:0)
要激活它,将图像视图放在单元格的底部并为其指定图像。另请确保将cellSeperatorStyle设置为无
那应该有用
答案 3 :(得分:0)
{ [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<image name>"]];
imgView.frame = CGRectMake(0, cellHeight, cellWidth, 1);
[customCell.contentView addSubview:imgView];
return customCell;
}
}
答案 4 :(得分:0)
首先,您必须通过以下代码
使SeparatorStyle为none[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
之后添加图像也是每个单元格的结尾
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.....
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater.png"]];
[imgView sizeToFit];
[Cell.contentView addSubview:imgView];
.....
}