原文链接:http://blog.csdn.net/m372897500/article/details/46710055
两种方式,看你的tableView是哪种样式。 如果是UITableViewStylePlain,你可以将UITableViewCell的separator设置为UITableViewCellSeparatorStyleNone。将tableViewCell的背景色,contentView的背景色设置为透明,在contentView中添加一个UIImageView做为背景,使UIImageView的高度小于cell的高度,这样创建出的tableView就可以使每个cell之间看起来有一定间隔。这个间隔就是imageView的高度与cell的高度之间的差值。 如果你的tableView样式是UITableViewStyleGrouped,那就更好办了,因为group的tableView每个section都是隔开的,你只需要给每个section添加一行cell就行了。如果需要调整section之间的距离,你可以用UITableView的属性sectionHeaderHeight或sectionFooterHeight来设置。也可以用delegate方法来设置高度,heightForHeaderInSection或heightForFooterInSection
不过我这里的需求稍微发生了一点变化 不但要设置cell之间的距离 这个一小段距离的颜色也要不一样 UI效果图是淡淡的灰色,由于我的UITableView 是plain 所以采用了上面的第一种方式 代码如下:
cell.backgroundColor = [UIColor clearColor];
// cell.contentView.backgroundColor = [UIColor clearColor];
CGFloat screenWidth = [UIScreen mainScreen].applicationFrame.size.width;
UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 140, screenWidth-30, 10)];
imageview.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:imageview];