I\'m trying to set a tintColor on my UIRefreshControl (building on iOS 7).
I enabled refreshing for the tableViewController in storyboard, then in my ViewController vi
@william-george's answer set me in the right direction, but was giving me weird autolayout animation issues.
So here's the version that worked for me:
- (void)programaticallyRefresh {
// Hack necessary to keep UIRefreshControl's tintColor
[self.scrollView setContentOffset:CGPointMake(0, -1.0f) animated:NO];
[self.scrollView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];
[self.refreshControl beginRefreshing];
[self refresh];
}
-refresh
is the method tied to the UIRefreshControl
.
When I set
tableView.refreshControl = refreshControl
several times where refreshControl is a different instance each time, I had the issue when refresh control color was always black and setting tint color to a different value didn't help.
So that I set tableView.refreshControl = refreshControl
only once and when I need to hide it I set alpha value, more details in this thread:
How do I "hide" a UIRefreshControl?
Using UIView.animate
didn't work for me on Swift 4.
Here's what I ended up using
extension UIRefreshControl {
func beginRefreshingManually(with scrollView: UIScrollView, isFirstTime: Bool) {
if self.isRefreshing { return }
// Workaround: If we call setContentOffset on the first time that the screen loads
// we get a black refreshControl with the wrong size.
// We could just set the scrollView.contentOffset everytime, but it does not animate the scrolling.
// So for every other time, we call the setContentOffset animated.
if isFirstTime {
scrollView.contentOffset = CGPoint(x: 0, y: -self.frame.size.height)
} else {
scrollView.setContentOffset(CGPoint(x: 0, y: -self.frame.size.height), animated: true)
}
self.beginRefreshing()
}
}
Solution for the tintColor issue: add this in viewDidLoad
[self.refreshControl setTintColor:[UIColor whiteColor]];
[self.refreshControl tintColorDidChange];
Now you have a white indicator when you call beginRefresh manually.
i found some Work Around i hope it works for you
[_TBL setContentOffset:CGPointMake(0,_TBL.contentOffset.y-_refreshControl.frame.size.height) animated:YES];
[_refreshControl performSelector:@selector(beginRefreshing) withObject:nil afterDelay:0.25];
[self getLatestUpdates];
Set manually content offset for your tableView/scrollView before begin spinning:
tableView.setContentOffset(CGPoint(x: 0, y: tableView.contentOffset.y - (refreshControl.frame.size.height)), animated: true)
refreshControl.beginRefreshing()
......