tableViewCell 下划线 长度设置为屏幕的宽

直接复制到项目中即可使用

OC

  -(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    if([tableView respondsToSelector:@selector(setSeparatorInset:)]){     
      [tableView setSeparatorInset:UIEdgeInsetsZero];  
    }  
    if([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
      [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)
cell forRowAtIndexPath:( NSIndexPath*)indexPath{
  if([cell respondsToSelector:@selector(setSeparatorInset:)]) {
      [cell setSeparatorInset:UIEdgeInsetsZero];
  }   
  if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
      [cell setLayoutMargins:UIEdgeInsetsZero];
  }
}

swift

override func viewDidLayoutSubviews() {   
   super.viewDidLayoutSubviews() 
   if tableView.respondsToSelector("setSeparatorInset:"){   
       tableView.separatorInset = UIEdgeInsetsZero     
   }    
  if tableView.respondsToSelector("setLayoutMargins:"){
        if #available(iOS 8.0, *) {
            tableView.layoutMargins = UIEdgeInsetsZero  
      } else {  
          // Fallback on earlier versions   
     } 
   }
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell,
 forRowAtIndexPath indexPath: NSIndexPath) {
    if tableView.respondsToSelector("setSeparatorInset:"){
        tableView.separatorInset = UIEdgeInsetsZero
    }
    if tableView.respondsToSelector("setLayoutMargins:"){
        if #available(iOS 8.0, *) { 
           tableView.layoutMargins = UIEdgeInsetsZero
        } else {
            // Fallback on earlier versions
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //更改tableview分割线颜色等等属性 self.tableView.separatorColor = UI...
    然亦伞阅读 3,630评论 1 1
  • 我是一个无趣的人,不追星,那些疯狂追星的行为估计永远不会出现在我的身上。但是,从小到大,我都特别崇拜我的父母,把他...
    木木夕啊阅读 3,443评论 3 3
  • 前言 曾经做过一个图片编辑软件,对图片进行添加贴纸 滤镜等功能,其中遇到一个问题,因为对图片质量要求较高,需要对原...
    ashura_阅读 5,396评论 0 5
  • 有些电影会给人们很大的启发,有些电影却让人明白人生的道理,而《楚门的世界》却告诉我们人心是无法被别人操控的,就...
    曲亚轩阅读 2,415评论 0 0
  • 今晚妹妹的大女儿从学校回来了。晚上后我和她说,冉冉,大姨教你做蛋糕吧,以后到美国用得上。她很高兴说,好啊,好...
    童童妈DX阅读 1,352评论 0 0