• 【2021】IOS技术 UITableViewCell分割线无留白技巧


    IOS技术 UITableViewCell分割线无留白技巧

    开发工具 : Xcode 14.2
    编程语言 : Swift 5
    UIKit控件 : UITableView

    1. UITableViewCell默认分割线

    展示效果

    实际使用中的问题

    1、分割线头部有留白,逼死强迫症
    2、没有内容的Cell分割线仍然存在,使用完全没有体验性可言

    源码Code

        /// 考试列表
        var table =  UITableView()
        
        // MARK: --页面载入方法
        /// 页面载入方法
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
            table = UITableView.init(frame: CGRect(x: 0,y: 0, UIScreen.main.bounds.width,height: UIScreen.main.bounds.height))
            table.dataSource = self
            table.delegate = self
            table.separatorStyle = UITableViewCell.SeparatorStyle.singleLine
            table.allowsSelection = false
            self.view.addSubview(table)
        }
        
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 10
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = UITableViewCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: nil)
            let lblExamTitle = UILabel.init(frame: CGRect(x: 45, y: 15,  200, height: 20))
            lblExamTitle.text = "cell(indexPath.row)"
            cell.addSubview(lblExamTitle)
            return cell
        }
        
    

    1. UITableViewCell调整后分割线

    调整后展示效果

    处理方式

    1、补足留白
    2、无内容的Cell不显示分割线

    调整后源码Code

        var table =  UITableView()
        
        // MARK: --页面载入方法
        /// 页面载入方法
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
            table = UITableView.init(frame: CGRect(x: 0,y: 0, UIScreen.main.bounds.width,height: UIScreen.main.bounds.height))
            table.dataSource = self
            table.delegate = self
            table.separatorStyle =  UITableViewCell.SeparatorStyle.singleLine
            table.separatorInset=UIEdgeInsets.zero
            table.tableFooterView = UIView(frame: CGRect.zero)
            table.allowsSelection = false
            self.view.addSubview(table)
        }
        
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 10
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = UITableViewCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: nil)
            let lblExamTitle = UILabel.init(frame: CGRect(x: 45, y: 15,  200, height: 20))
            lblExamTitle.text = "cell(indexPath.row)"
            cell.addSubview(lblExamTitle)
            return cell
        }
    
    自由、人生、意义、执着、残缺美 一个人认真的学习者 --------2015年3月19日
  • 相关阅读:
    python爬虫实战(八)--------知乎
    python爬虫实战(七)--------伯乐在线文章(模版)
    python分布式爬虫打造搜索引擎--------scrapy实现
    VS2010与SVN
    ASP.net 自定义控件GridView
    Asp.net Ajax提供PageMethods调用
    JSON串行化
    JOSN反串行化
    WebRequestManager对象的使用
    WebRequest调用
  • 原文地址:https://www.cnblogs.com/littlemo/p/14453101.html
Copyright © 2020-2023  润新知