• 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
            }
        }
    

     

  • 相关阅读:
    pku3734Blocks
    STLmultiset
    zoj 2744
    EXCEL vba 插入图片的大小裁剪尺寸移动和旋转的设置和指定
    C# WinForm下Excel导入导出
    日期格式校验
    vb获取目录下所有文件夹名称的方法
    批量 生成 word 多线程
    Java中验证日期时间格式
    递归绑定树形菜单
  • 原文地址:https://www.cnblogs.com/Rong-Shengcom/p/9309862.html
Copyright © 2020-2023  润新知