19

在 IOS7 中,UITableView 在使用 style=grouped 时不再有缩进。如何启用缩进,以便 UITableView 的行为类似于苹果的设置应用程序?

4

3 回答 3

16

有一种更简单的方法可以实现这一点。

  1. 将您的 UITableView 远离两侧。例如:使用自动布局,您将拥有 15 像素的前导和尾随空间(或任何您想要的空间)。您现在正在创建 Apple 过去免费为您提供的带有分组表视图的“缩进”。

  2. 调整图层以添加角和边框。

[[[self tableView] layer] setCornerRadius:5.0f];
[[[self tableView] layer] setBorderWidth:0.5f];
[[[self tableView] layer] setBorderColor:[[UIColor redColor] CGColor]];

(我无法发布结果图片,因为我还没有足够的声誉)

于 2013-10-08T10:19:57.770 回答
1

答案位于此处,如果您仍在寻找解决方案,

http://i-phone-dev.blogspot.no/2014/04/keep-ios-6-uitableview-styles-in-ios-7.html

于 2014-04-01T12:21:33.907 回答
0

内部cellForRowAtIndexPath方法,试试这个:

CALayer *sublayer = [CALayer layer];
UIImage *img = [UIImage imageNamed:@"blue_box_6dbcef.png"];
sublayer.backgroundColor = [[UIColor alloc] initWithPatternImage:img].CGColor;
sublayer.frame = CGRectMake(10,0,container.frame.size.width-20, 112);
//sublayer.cornerRadius = 5; // For rounded corners
UIView *bgview = [[UIView alloc] init];
bgview.backgroundColor = [UIColor clearColor];
[bgview.layer addSublayer:sublayer];
cell.backgroundView = bgview;

这将在单元格的两侧(左/右)添加 10pt 的边距。

于 2013-10-03T20:39:09.983 回答