iOS 7 UIRefreshControl tintColor not working for beginRefreshing

前端 未结 19 1706
我在风中等你
我在风中等你 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: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()
        }
    }
    

提交回复
热议问题