1

I wanted to set only right border in UITableView?

So far i have tried this below code. But it is setting the border in whole table as it is there in mac, But i wanted to achieve that it should set only right border :-

self.tableView.layer.borderWidth = 1.0;
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56

2 Answers2

5

instead of using layer you can add a view to the contentView of the cell the size you want, this add border of 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];
Ilario
  • 5,979
  • 2
  • 32
  • 46
2

As I know, you can't add border for one side of UITableView only. Check this answer here, it could help you

UITableView one sided Border color?

Community
  • 1
  • 1
Sawsan
  • 1,096
  • 10
  • 20