Swift3.0 -- UIRefreshControl添加下拉刷新控件

首先,声明一个UIRefreshControl变量属性

/// 刷新控件
    var refreshControl: UIRefreshControl?

设置刷新控件

//设置刷新控件
        // 1>实例化控件
        refreshControl = UIRefreshControl();
        
        // 2>添加到视图
        tableView?.addSubview(refreshControl!);
        
        // 3>添加监听方法
        refreshControl?.addTarget(self, action: #selector(loadData), for: .valueChanged);
UIRefreshControl头文件

import Foundation
import UIKit

//
//  UIRefreshControl.h
//  UIKit
//
//  Copyright 2012-2015 Apple Inc. All rights reserved.
//

@available(iOS 6.0, *)
open class UIRefreshControl : UIControl {

    
    /* The designated initializer
     * This initializes a UIRefreshControl with a default height and width.
     * Once assigned to a UITableViewController, the frame of the control is managed automatically.
     * When a user has pulled-to-refresh, the UIRefreshControl fires its UIControlEventValueChanged event.
     *
    */
    public init()

    
    open var isRefreshing: Bool { get }

    
    open var tintColor: UIColor!

    open var attributedTitle: NSAttributedString?

    
    // May be used to indicate to the refreshControl that an external event has initiated the refresh action
    @available(iOS 6.0, *)
    open func beginRefreshing()

    // Must be explicitly called when the refreshing has completed
    @available(iOS 6.0, *)
    open func endRefreshing()
}
When a user has pulled-to-refresh, the UIRefreshControl fires its UIControlEventValueChanged event.

当执行拉动刷新操作时,UIRefreshControl会相应UIControlEventValueChanged事件。

所以 addTarget 方法 UIControlEvents 枚举中选择 .valueChanged


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值