UIRefreshControl on UICollectionView only works if the collection fills the height of the container
Try this:
self.collectionView.alwaysBounceVertical = YES;
Complete code for a UIRefreshControl
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor grayColor];
[refreshControl addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
self.collectionView.alwaysBounceVertical = YES;
Attributes/Scroll View/Bounce Vertically in Storyboard/Xib
Larry's answer in swift:
let refreshControl = UIRefreshControl()
refreshControl.tintColor = UIColor.blueColor()
refreshControl.addTarget(self, action: "refresh", forControlEvents: .ValueChanged)
collectionView.addSubview(refreshControl)
collectionView.alwaysBounceVertical = true
Swift 3:
let refreshControl = UIRefreshControl()
refreshControl.tintColor = .blue
refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
collectionView.addSubview(refreshControl)
collectionView.alwaysBounceVertical = true
If your collectionview
has a content size big enough to scroll vertically, it's OK, but in your case it's not.
You must enable the property AlwaysBounceVertical
, so you could set self.collectionView.alwaysBounceVertical = YES;