zoukankan      html  css  js  c++  java
  • 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.
        }
        
    
       
    
    }
  • 相关阅读:
    npm版本管理
    spring框架学习笔记5:SpringAOP示例
    spring框架学习笔记4:SpringAOP实现原理
    spring框架学习笔记3:使用注解代替配置文件
    spring框架学习笔记2:配置详解
    spring框架学习笔记1:搭建测试
    struts2框架学习笔记7:struts2标签
    struts2框架学习笔记6:拦截器
    struts2框架学习笔记5:OGNL表达式
    struts2框架学习笔记4:获取参数
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7084761.html
Copyright © 2011-2022 走看看