您需要添加獨立的視圖作爲分隔符 首先要tableViews分隔符來沒有
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell addSubview:[self drawSeparationView:(indexPath.row)]];
return cell;
}
然後提請分隔符
- (UIView*)drawSeparationView:(NSInteger)itemNo {
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, self.tableView.frame.size.width, cellHeight);
UIView *upperStrip = [[UIView alloc]init];
upperStrip.backgroundColor = [UIColor colorWithWhite:0.138 alpha:1.000];
upperStrip.frame = CGRectMake(0, 0, view.frame.size.width, 2);
[view addSubview:upperStrip];
UIView *lowerStrip = [[UIView alloc]init];
lowerStrip.backgroundColor = [UIColor colorWithWhite:0.063 alpha:1.000];
lowerStrip.frame = CGRectMake(0, cellHeight-2, view.frame.size.width, 2);
[view addSubview:lowerStrip];
return view;
}
的輸出將是這樣的
非常感謝@Bishal – DipakSonara