ios 7 - uitableviewCell分隔线

时间:2014-06-30 11:15:47

标签: iphone uitableview ios7

我需要在iOS 7中显示与iOS 6相同的分隔线(如我的图像2)。我在CellForRowAtIndexPath中使用下面的代码:

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0];
[cell.contentView addSubview:separatorLineView];

UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_highlighted.png"]];
cell.selectedBackgroundView = customColorView;

cell.backgroundColor=[UIColor clearColor];

//Separation style for iOS7
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
}

return cell;

我的输出如下图所示:

enter image description here

但我的输出应该是IOS 6和7的下图:

enter image description here

任何人都可以帮我解决这个问题吗?感谢..

2 个答案:

答案 0 :(得分:1)

contentView并不总是与单元格本身相同,在内容视图上方的单元格视图顶部添加分隔符视图:

separatorLineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell insertSubview:separatorLineView aboveSubview:cell.contentView];

答案 1 :(得分:0)

UITableView有一个属性separatorInset。使用它将表视图分隔符的insets设置为零,使它们跨越屏幕的整个宽度。

[tableView setSeparatorInset:UIEdgeInsetsZero];

OR

您也可以在xib中设置分隔符插入属性。将其更改为自定义。并使左右值都为零。

相关问题