iOS 7 UIRefreshControl tintColor not working for beginRefreshing

前端 未结 19 1583
我在风中等你
我在风中等你 2020-12-04 13:48

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

相关标签:
19条回答
  • 2020-12-04 14:21

    @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.

    0 讨论(0)
  • 2020-12-04 14:22

    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?

    0 讨论(0)
  • 2020-12-04 14:23

    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()
        }
    }
    
    0 讨论(0)
  • 2020-12-04 14:25

    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.

    0 讨论(0)
  • 2020-12-04 14:25

    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];
    
    0 讨论(0)
  • 2020-12-04 14:27

    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()
    ......
    
    0 讨论(0)
提交回复
热议问题