UITableViewCell分割線的常用操作

1、隱藏UITableViewCell分割線

? ? ? self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;

2、UITableViewCell分割線左邊對齊

第一種方法:

//在創(chuàng)建talbleView的下方添加這兩個(gè)if

if ([myTableView respondsToSelector:@selector(setSeparatorInset:)]) {

myTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

}

if ([myTableView respondsToSelector:@selector(setLayoutMargins:)]) {

[myTableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];

}

//實(shí)現(xiàn)tableview的代理方法

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

}

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];

}

}

第二種方法

cell.preservesSuperviewLayoutMargins=NO;

cell.separatorInset=UIEdgeInsetsZero;

cell.layoutMargins=UIEdgeInsetsZero;

3、修改UITableViewCell分割線的顏色

[self.tableviewsetSeparatorColor:[UIColor colorWithHexString:@"eeeeee"]];

4、隱藏表視圖多余單元格的分割線,此方法在創(chuàng)建talbeview的后面調(diào)用

- (void)setExtraCellLineHidden: (UITableView*)tableView{

UIView*view = [UIViewnew];

view.backgroundColor= [UIColorclearColor];

[tableViewsetTableFooterView:view];

}

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

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

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