UITableViewCell添加了自定义视图加载问题

用户名

您好,我想UITableView在我的cllforRowAtIndex代表中为我的So添加自定义单元格分隔符

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]
}

之后UIView,我要向我的cell.content视图添加自定义

 UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];

    lineView.backgroundColor = [UIColor colorWithRed:61.0/255 green:80.0/255 blue:118.0/255 alpha:1.0];
    [cell.contentView addSubview:lineView];

但是我的问题是,当它第一次加载时,我的分隔符右侧不会移到的edg位置,UITableView但是一旦我滚动了表格,它就会转到整个宽度。这是为什么?我该如何解决?

Rafa de King
  1. 创建一个自定义 UITableViewCell

  2. layoutSubviews在单元格的方法中设置分隔符的框架

或者在这种情况下,您也可以像这样更改分隔符的颜色:

[self.tableView setSeparatorColor:[UIColor myColor]];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章