解决难以统一配置 UITableView 的 separatorInset 的问题
过去可能需要在这些 UIViewController 里写:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
现在只需继承 CustomSeperatorInsetTableView,将代码配置为 mySeparatorInset 为你希望的值,默认值为 UIEdgeInsetsZero,
另外你也可以在 IB 中修改 UITableView 的 Class 为 CustomSeperatorInsetTableView,右侧填入你希望的 separatorLeft 和 separatorRight 值,不填默认为 0