【问题标题】:UITableView unwanted white line on each line separatorUITableView 每个行分隔符上不需要的白线
【发布时间】:2014-06-27 13:43:11
【问题描述】:

我一直在用下面的代码来做tableview

 _comboBoxTableView = [[UITableView alloc] initWithFrame:CGRectMake(1, _selectContentLabel.frame.origin.y+_selectContentLabel.frame.size.height-1, frame.size.width+1, 48) style:UITableViewStylePlain];
_comboBoxTableView.layer.borderColor=[UIColor colorWithRed:226.0/255.0 green:226.0/255.0 blue:226.0/255.0 alpha:1].CGColor;
_comboBoxTableView.layer.cornerRadius = 10;
_comboBoxTableView.layer.borderWidth = 1.0f;
_comboBoxTableView.separatorColor = [UIColor colorWithRed:166.0/255.0 green:166.0/255.0 blue:166.0/255.0 alpha:1];
[_comboBoxTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

每个分隔符的左侧都有一个不需要的白色,如下所示。

这是一个错误吗?我正在使用 ios7.1 运行它。有什么解决办法吗?

【问题讨论】:

    标签: ios objective-c ipad uitableview ios7.1


    【解决方案1】:

    这不是错误。从 iOS 7 开始,表格视图能够调整其分隔符的插入。如果您想要边到边分隔符,请消除插入:

    if ([_comboBoxTableView respondsToSelector:@selector(separatorInset)]) { // In case running iOS < 7
        _comboBoxTableView.separatorInset = UIEdgeInsetsZero;
    }
    

    更多信息请关注UITableView documentation

    【讨论】:

      【解决方案2】:

      万一您没有时间以编程方式解决此问题,您可以添加子视图修补 while 行。

      我知道这不是正确的解决方案,但有效。

      【讨论】:

        【解决方案3】:

        什么对我有用:在 Interface Builder 中,tableview 有一个叫做 Separator Inset 的东西。它通常处于默认状态(这似乎是 15)。

        您可以将其切换为自定义并将 15 替换为 0。不再有奇怪的行。

        【讨论】:

          【解决方案4】:

          如果有人需要非零分隔符插入,则那些白线是 UITableCell,它未被单元格内容视图和分隔符覆盖。只需在文档大纲(不是内容视图!)中选择 UITableCell 并将其设置为与内容视图的背景相同的背景颜色(或您想要的任何颜色)。

          【讨论】:

            猜你喜欢
            • 2011-06-15
            • 2021-10-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-09-04
            • 2014-11-19
            • 2017-03-12
            相关资源
            最近更新 更多