在做APP的個(gè)人中心或者其它頁(yè)面的時(shí)候會(huì)要求頁(yè)面cell的分割線是從左邊0開(kāi)始的,但是系統(tǒng)默認(rèn)是間隔了15像素的距離的,如下圖1-1
圖1-1
可能大家都會(huì)說(shuō)自定義cell就搞定了啊,沒(méi)錯(cuò)兜叨,但是有沒(méi)有更加好一點(diǎn)的方法呢?畢竟自定義cell費(fèi)時(shí)間疤鼻蕖(其實(shí)是懶)初嘹,其實(shí)辦法還是有的及汉,而且也簡(jiǎn)單,在iOS7中可以通過(guò)設(shè)置setSeparatorInset:
為UIEdgeInsetsZero
削樊,在iOS8改成setLayoutMargins:
方法了豁生,為了兼容iOS7兔毒,所以要加個(gè)判斷漫贞,具體代碼在tableView頁(yè)面添加下面的方法即可:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
- (void)viewDidLayoutSubviews
{
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
完成之后效果如圖1-2,是不是很省事育叁?:
圖1-2