如何在iOS中为Cell Separator设置图像

Har*_*nan 1 uitableview ios

在我的表格视图中,我需要将单元格分隔符设置为我随身携带的图像.我怎样才能做到这一点?

man*_*jmv 8

一个简单的解决方案是您可以将图案图像设置为单元格分隔符.

[tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:...]]];
Run Code Online (Sandbox Code Playgroud)

或者您只需在单元格内容视图中添加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];
Run Code Online (Sandbox Code Playgroud)

  • @HarikrishnanT这是ios 7的问题.你应该将它用于iOS7 - `if([tblvw respondsToSelector:@selector(setSeparatorInset :)])[tblvw setSeparatorInset:UIEdgeInsetsZero];` (2认同)