Ios – UITableView section border

iosuitableview

Is there any way to set a border on a UITableView section (group style)? I don't mean change the border on the cells in the section – I want a border around the whole section. Like this:

Bordered UITableView section

Note: While the picture above only shows part of a single section, the table in question actually has multiple sections, each of variable lengths, which I would like to border separately.

Best Answer

Yes you can achieve it with couple of line of codes :

Simply have the TableView in your Xib file.No need to have the UITableView Style to Grouped.

1) Import the QuartzCore framework in your .h file.

#import <QuartzCore/QuartzCore.h>

2) Now set the Layers of the TableView in .m file.

[CategoryTblView.layer setBorderWidth: 1.0];
[CategoryTblView.layer setCornerRadius:8.0f];
[CategoryTblView.layer setMasksToBounds:YES];
[CategoryTblView.layer setBorderColor:[[UIColor blackColor] CGColor]];

And this is the output :

enter image description here