IOS7 UITableView grouped like in Settings App

安稳与你 提交于 2019-11-29 11:16:34

问题


In IOS7 the UITableView does not have indentation anymore when using style=grouped. How can enable the indentation, so that the UITableView behaves like the settings app from apple?


回答1:


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)




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/19016313/ios7-uitableview-grouped-like-in-settings-app

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