2014-06-30 43 views
0

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

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

任何人都可以请帮我怎么做到这一点?谢谢..

回答

1

contentView并不总是有大小的细胞本身一样,在内容视图上方的单元格视图的顶部添加分隔视图:

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

Thanks @ A-Live我已经根据你改变了它,仍然得到相同的输出。 – user2786

+0

@ user2786确保您在视图层次结构中具有有效的宽度和顺序。增加了一些代码,如有需要,随时提供详细信息。 –

0

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

[tableView setSeparatorInset:UIEdgeInsetsZero];

OR

可以在厦门国际银行还设置分离器插入属性。将其更改为自定义。并将左右值都设为零。