如何在UITableView中只设置右边框?

时间:2013-11-29 14:14:34

标签: ios iphone ipad

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

到目前为止,我已尝试过以下代码。但它在整个表格中设置边框,因为它在mac中,但我想实现它应该只设置正确的边框: -

self.tableView.layer.borderWidth = 1.0;

2 个答案:

答案 0 :(得分:5)

而不是使用图层,您可以将视图添加到您想要的单元格的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];

答案 1 :(得分:2)

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

UITableView one sided Border color?

相关问题