IOS7 UITableView grouped like in Settings App

岁酱吖の 提交于 2019-11-30 08:13:22

There is a much simpler way to achieve this.

  1. Place your UITableView away from the sides. eg: using Autolayout you'd have a leading and trailing space of 15px (or whatever you want). You're now creating the 'indentation' that Apple used to give you for free with grouped table views.

  2. Adjust the layer to add corners and a border.

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

(I can't post an image of the result because I don't yet have enough reputation)

An answer is located here, if you still looking for a solution,

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

Inside cellForRowAtIndexPath method, try this:

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;

That will add a 10pt margin on both sides (left/right) of the cell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!