UITableView分割線問題

在實際開發(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];
    }
}
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容