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

   

}

 

转载于:https://www.cnblogs.com/xujiahui/p/7084761.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值