Reprinted from: http://blog.csdn.net/smiling8866/article/details/51548234
1. Problems encountered
When I use the third-party FPPopoverController to display UITableView, the left side of the cell's dividing line is not full, but the right side is full. This looks ugly. I need to make it underfilled on the left and right sides, and the distance is 15 pixels.
Second, the solution
1. Add the following code to the viewDidLoad method of UITableView:
// code1 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } // code2 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 15)]; }
2. Add a proxy method of UITableView:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 15)]; } }
Third, the analysis of the solution
Code at code1:
Customize the frame of the cell dividing line
code2处代码:
-layoutMargins returns a set of insets from the edge of the view’s bounds that denote a default spacing for laying out content.
If preservesSuperviewLayoutMargins is YES, margins cascade down the view tree, adjusting for geometry offsets, so that setting the left value of layoutMargins on a superview will affect the left value of layoutMargins for subviews positioned close to the left edge of their superview’s bounds
If your view subclass uses layoutMargins in its layout or drawing, override -layoutMarginsDidChange in order to refresh your view if the margins change.
*Note: Later, I found a simpler way, that is, the Seperator insert can be adjusted in the storyboard