如何在UITableView中只设置右边框? [英] How to set only right border in UITableView?

查看:108
本文介绍了如何在UITableView中只设置右边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanted to set only right border in UITableView?

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

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;


推荐答案

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

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];

这篇关于如何在UITableView中只设置右边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆