在開發(fā)過程中,UITableViewCell的分割線左邊缺失一部分很讓人惱火,有時又有可能讓分割線居中.第一種解決辦法是:將系統(tǒng)分割線隱藏,自己再畫一條.
第二種解決辦法是:修改系統(tǒng)的分割線,將分割線拉長或縮短.
第一種解決方法就不說了,相信大家都會,再次說明下第二種.
方法如下:
@interface MATableViewController ()
@property (nonatomic, assign) UIEdgeInsets insets;
@end
@implementation MATableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.insets = UIEdgeInsetsMake(0, 15, 0, 15); //只有左右間距可用,如果想將兩邊都補齊則設置為UIEdgeInsetsMake(0, 0, 0, 0)即可
}
#pragma mark 用于將cell分割線補全
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:self.insets];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:self.insets];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:self.insets];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:self.insets];
}
}