Skip to content

Instantly share code, notes, and snippets.

@Baza207
Last active September 14, 2016 15:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Baza207/f5ff5abf7b8c44e2ffb3 to your computer and use it in GitHub Desktop.
Save Baza207/f5ff5abf7b8c44e2ffb3 to your computer and use it in GitHub Desktop.
A Swift extension for UICollectionViewController to allow setting and getting a UIRefresh control in the same manor as UITableViewController.
///
/// Extention functions for UICollectionViewController
///
extension UICollectionViewController {
/// Allows easy access to a collection view controller's refrsh control the same way as in a table view controller.
var refreshControl: UIRefreshControl? {
get {
return collectionView?.viewWithTag(140412014669856) as? UIRefreshControl
}
set {
if let oldRefreshControl = collectionView?.viewWithTag(140412014669856) as? UIRefreshControl {
oldRefreshControl.removeFromSuperview()
collectionView?.alwaysBounceVertical = false
}
if let refreshControl = newValue {
refreshControl.tag = 140412014669856
collectionView?.addSubview(refreshControl)
collectionView?.alwaysBounceVertical = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment