去掉UITableViewCell左側會有默認15像素的空白,ios8之後新的解決方法

在ios7中,UITableViewCell左側會有默認15像素的空白。這時候,設置setSeparatorInset:UIEdgeInsetsZero 能將空白去掉。

但是在ios8中,設置setSeparatorInset:UIEdgeInsetsZero 已經不起作用了。下面是解決辦法

1:這個我自己的方法

直接在cellForRowAtIndexPath方法中添加:


    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([self.table respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.table setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }

搞定

2:下面百其他iOS工程師的方法

首先在viewDidLoad方法中加上如下代碼:

然後在willDisplayCell方法中加入如下代碼:

這樣,空白就沒有了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章