iOS分割线的操作方式

来源:互联网 发布:jdk 7u79 windows x32 编辑:程序博客网 时间:2024/04/30 15:25
  • 让分割线紧贴屏幕
// 清空分割线的边距- (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(0);        make.right.equalTo(self.mas_right).offset(0);        make.bottom.equalTo(self.mas_bottom).offset(0);        make.height.offset(1 / [UIScreen mainScreen].scale);    }];
0 0