【问题标题】:How to set only right border in UITableView?如何在 UITableView 中仅设置右边框?
【发布时间】:2013-11-29 14:14:34
【问题描述】:

我只想在 UITableView 中设置右边框?

到目前为止,我已经尝试过以下代码。但它在整个表格中设置边框,就像在 mac 中一样,但我想实现它应该只设置右边框:-

self.tableView.layer.borderWidth = 1.0;

【问题讨论】:

    标签: ios iphone ipad


    【解决方案1】:

    您可以将视图添加到您想要大小的单元格的 contentView 中,而不是使用层,这会添加 1px 的边框:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
      ...
    
      UIView *right = [[UIView alloc] initWithFrame:CGRectMake(319, 0, 1, cell.frame.size.height)];
      right.backgroundColor = [UIColor redColor];
    
      [cell.contentView addSubview:right];
    

    【讨论】:

    • @"llario" 谢谢,但如果我想画同样的权利。但我还需要做什么??
    • @hussainShabbir 和 CGRectMake 你可以把边框放在你想要的任何地方。在本例中 x = 319,宽度为 1px,因此向右看
    • 谢谢,我已将 319 更改为 200,它工作正常:)
    【解决方案2】:

    据我所知,您不能只为 UITableView 的一侧添加边框。在这里检查这个答案,它可以帮助你

    UITableView one sided Border color?

    【讨论】:

    • 感谢您的回复:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 2016-04-15
    • 2011-04-23
    • 1970-01-01
    • 2021-07-11
    • 2015-08-12
    相关资源
    最近更新 更多