zoukankan      html  css  js  c++  java
  • swift开发UITableViewCell的分割线与屏幕边缘对齐显示的解决方案 —— Swift

    swift开发UITableViewCell的分割线与屏幕边缘对齐显示的解决方案

     

    iOS开发中我们使用UITableView控件时会发现每个UITableviewCell的分割线左侧距离屏幕有一定的间距,这样的默认效果也很好,但是往往我们会遇到让把cell的分割线与屏幕的左右边缘对齐就是让分割线的宽度和屏幕的宽度相同的显示效果。

     

    介绍两种实现的方法:

    第一种方法:

    可以通过在cell中自定义一个cell底部subView的方法,使得subView的左右约束与屏幕的左右间距为0来实现,此种方法就不做重点说明。

     

    第二种方法:

    通过实现UITableViewDelegate中的代理方法来实现

     

    optional public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

     

    具体实现如下代码:

    //分割线从左端顶部显示(使cell的)分割线与屏幕的左右两端对齐显示
        func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
            
            if(cell.responds(to: #selector(setter: UITableViewCell.separatorInset))){
                cell.separatorInset = .zero
            }
            if(cell.responds(to: #selector(setter: UITableViewCell.layoutMargins))){
                
                cell.layoutMargins = .zero
            }
        }
    

     

  • 相关阅读:
    ASFNU SC Day6
    ASFNU SC Day3
    ASFNU SC Day2
    ASFNU SC Day1
    2017-9-3 校内模拟T2取数win
    2017-9-3 校内模拟T1卡片card
    (补题)苗条的树(poj_3522)
    跳跳棋(9018_1563)(BZOJ_2144)
    Java之JSP和Servlet基础知识。
    JSP中的九大内置对象
  • 原文地址:https://www.cnblogs.com/Rong-Shengcom/p/9309862.html
Copyright © 2011-2022 走看看