在實際開發(fā)中由于UI設計我們很少會使用系統(tǒng)自帶的分割線,之前都是隱藏系統(tǒng)分割線(_tabbleView.separatorStyle = UITableViewCellSeparatorStyleNone;)然后自己在cell中添加一個的View設置背景色與高度進而達到效果分割線的效果。當我們需要的是兩端到頂?shù)姆指罹€時,可以直接修改系統(tǒng)的分割線。當然如果需要的并不是兩端到頂?shù)奈覀冎灰匦略O置UIEdgeInsets * set = UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right);替換UIEdgeInsetsZero以達到所要實現(xiàn)的效果。
設置兩端間距為0的代碼??
// 設置分割線顏色
_groupsTableView.separatorColor = [UIColor colorWithHexString:@"2c2c2d"];
#pragma mark - 設置分割線的方法
-(void)viewDidLayoutSubviews {
if ([_groupsTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_groupsTableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([_groupsTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_groupsTableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}