• Swift tableview自带的刷新控件


    import UIKit
    
    class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
        let tableview = UITableView(frame: ScreenRect, style: .plain)
        let refreshControl = UIRefreshControl()
        let cell = "cell"
        var arraymutable = ["11","22","33","44","55"]
        let array = ["22","33","55","88"]
        
        
        override func viewDidLoad() {
            super.viewDidLoad()
    self.view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
            CreatUi()
            
            // Do any additional setup after loading the view.
        }
        
        func CreatUi(){
            
            tableview.separatorStyle = .singleLine
            tableview.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
            tableview.delegate = self
            tableview.dataSource = self
            tableview.tableFooterView = UIView()
            tableview.refreshControl = refreshControl
            
            refreshControl.backgroundColor = UIColor.gray
            refreshControl.attributedTitle = NSAttributedString(string: "刷新一下:(NSDate())", attributes: [NSForegroundColorAttributeName:UIColor.white])//设置文字颜色
            refreshControl.tintColor = UIColor.green //小菊花的颜色
            refreshControl.tintAdjustmentMode = .dimmed //色彩调整模式
            
            refreshControl.addTarget(self, action: #selector(addcount), for: .valueChanged)
            
            view.addSubview(tableview)
            
            
            
            
        }
        
        func addcount(){
            
            arraymutable.append(contentsOf: array)
            tableview.reloadData()
            refreshControl.endRefreshing()
            
            
        }
        override var preferredStatusBarStyle: UIStatusBarStyle{
            
            return .default
        }
        
        
        //tableview 代理
        func numberOfSections(in tableView: UITableView) -> Int {
            return 2
        }
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return arraymutable.count
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
            let celll = tableView.dequeueReusableCell(withIdentifier: cell) ?? UITableViewCell(style: .default, reuseIdentifier:cell)
            
            celll.textLabel?.text = arraymutable[indexPath.row]
            celll.textLabel?.textColor = UIColor.red
            celll.textLabel?.font = UIFont.boldSystemFont(ofSize: 20)
            
            
            return celll
            
            
        }
        
        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 80
        }
        
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
        
    
       
    
    }
  • 相关阅读:
    python爬虫学习笔记(七)-数据提取之正则表达式
    python爬虫学习笔记(六)-Request库的用法
    python爬虫学习笔记(五)-URLError与Cookie
    python爬虫学习笔记(四)-urllib库的高级用法
    python爬虫学习笔记(三)-爬取数据之urllib库
    20183215 实验四《Python程序设计》实验报告
    20183215 实验二《Python程序设计》实验报告
    20183215 实验一《Python程序设计》实验报告
    文件读写
    类和正则表达(自动更正、代数运算)
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7084761.html
Copyright © 2020-2023  润新知