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

Hus*_*bir 1 iphone ipad ios

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

到目前为止,我已经尝试过以下代码.但它是在整个表中设置边界,因为它在mac中,但我想实现它应该只设置右边界: -

self.tableView.layer.borderWidth = 1.0;
Run Code Online (Sandbox Code Playgroud)

Ila*_*rio 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];
Run Code Online (Sandbox Code Playgroud)