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.
        }
        
    
       
    
    }
  • 相关阅读:
    如何阅读大型代码库?
    发现一个时隐时现的bug!
    写给开发者:记录日志的10个建议
    教你一眼认出英语单词的意思
    为什么我要使用一个20年前的IBM老键盘
    有了screen,妈妈再也不用担心我的学习啦
    一次优秀的代码提交应该包含什么?
    你需要的不是重构,而是理清业务逻辑
    Android中监听ListView滑动到底部
    Android中的Handler,Looper,Message机制
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7084761.html
Copyright © 2011-2022 走看看