【问题标题】:ios 7 - uitableviewCell Separator lineios 7 - uitableviewCell 分隔线
【发布时间】:2014-06-30 11:15:46
【问题描述】:

我需要在 iOS 7 中显示与 iOS 6 相同的分隔线(如图 2 所示)。我在 CellForRowAtIndexPath 中使用以下代码:

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0];
[cell.contentView addSubview:separatorLineView];

UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_highlighted.png"]];
cell.selectedBackgroundView = customColorView;

cell.backgroundColor=[UIColor clearColor];

//Separation style for iOS7
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
}

return cell;

我得到如下图的输出:

但是对于 IOS 6 和 7,我的输出应该如下图所示:

谁能帮助我如何实现这一目标?谢谢..

【问题讨论】:

    标签: iphone uitableview ios7


    【解决方案1】:

    contentView 并不总是与单元格本身具有相同的大小,请在内容视图上方的单元格视图顶部添加分隔符视图:

    separatorLineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [cell insertSubview:separatorLineView aboveSubview:cell.contentView];
    

    【讨论】:

    • Thanks@A-Live 我已根据您的要求更改了它,仍然得到相同的输出。
    • @user2786 确保您在视图层次结构中具有有效的宽度和顺序。添加了一些代码,如果需要,请随时询问详细信息。
    【解决方案2】:

    UITableView 有一个属性 separatorInset。使用它来将表格视图分隔符的 insets 设置为零,以让它们跨越屏幕的整个宽度。

    [tableView setSeparatorInset:UIEdgeInsetsZero];

    您也可以在 xib 中设置分隔符插入属性。将其更改为自定义。并使左右值都为零。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-10
      • 2014-02-10
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多