天天看點

iOS分割線的操作方式

  • 讓分割線緊貼螢幕
// 清空分割線的邊距
- (void)viewDidLoad {
self.tableView.separatorInset = UIEdgeInsetsZero;
self.tableView.layoutMargins = UIEdgeInsetsZero;
}
// cell将要顯示的時候會調用此方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.layoutMargins = UIEdgeInsetsZero;
    cell.separatorInset = UIEdgeInsetsZero;
}    

           
  • 隐藏分割線
- (void)viewDidLoad {
// 隐藏自帶的分割線
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
           
  • 自定義分割線
// 自己加一個分割線
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:line];

    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset();
        make.right.equalTo(self.mas_right).offset();
        make.bottom.equalTo(self.mas_bottom).offset();
        make.height.offset( / [UIScreen mainScreen].scale);

    }];