Class

UIRefreshControl

A standard control that can initiate the refreshing of a scroll view’s contents.

Declaration

class UIRefreshControl : UIControl

Overview

A UIRefreshControl object is a standard control that you attach to any UIScrollView object, including table views and collection views. Add this control to scrollable views to give your users a standard way to refresh their contents. When the user drags the top of the scrollable content area downward, the scroll view reveals the refresh control, begins animating its progress indicator, and notifies your app. You use that notification to update your content and dismiss the refresh control.

Illustration showing a refresh control. The control displays an animated progress indicator at the top of a scroll view's content area.

The refresh control lets you know when to update your content using the target-action mechanism of UIControl. Upon activation, the refresh control calls the action method you provided at configuration time. When adding your action method, configure it to listen for the valueChanged event, as shown in the following example code. Use your action method to update your content, and call the refresh control’s endRefreshing() method when you are done.

func configureRefreshControl () {
   // Add the refresh control to your UIScrollView object.
   myScrollingView.refreshControl = UIRefreshControl()
   myScrollingView.refreshControl?.addTarget(self, action:
                                      #selector(handleRefreshControl),
                                      for: .valueChanged)
}
    
@objc func handleRefreshControl() {
   // Update your content…

   // Dismiss the refresh control.
   DispatchQueue.main.async {
      self.myScrollingView.refreshControl?.endRefreshing()
   }
}

Topics

Initializing a Refresh Control

init()

Initializes and returns a standard refresh control.

Accessing the Control Attributes

var tintColor: UIColor!

The tint color for the refresh control.

var attributedTitle: NSAttributedString?

The styled title text to display in the refresh control.

Managing the Refresh Status

func beginRefreshing()

Tells the control that a refresh operation was started programmatically.

func endRefreshing()

Tells the control that a refresh operation has ended.

var isRefreshing: Bool

A Boolean value indicating whether a refresh operation has been triggered and is in progress.

See Also

Data

Filling a Table with Data

Create and configure cells for your table dynamically using a data source object, or provide them statically from your storyboard.

protocol UITableViewDataSource

The methods adopted by the object you use to manage data and provide cells for a table view.

protocol UITableViewDataSourcePrefetching

A protocol that provides advance warning of the data requirements for a table view, allowing you to start potentially long-running data operations early.

class UILocalizedIndexedCollation

An object that organizes, sorts, and localizes the data for a table view that has a section index.

protocol UIDataSourceTranslating

An advanced interface for managing a data source object.