UIRefreshControl 的色调颜色无法初始设置



我目前正在努力解决一个我无法处理的问题,我找不到任何答案或解决方法。

问题是我想将刷新控件的颜色更改为 .white,例如,我在每个视图控制器的viewDidLoad()中调用beginRefreshingManually()函数,但初始颜色仍然是黑色。尝试手动拉取以刷新时,刷新控件变为 .white

以下是我编写的一些代码:

extension UIScrollView {
func setupRefreshControl(withTintColor tintColor: UIColor = JDColorConstants.UIScrollView.refreshControlWhiteColor.color,
completion: @escaping (() -> Void)) {
let refreshControl = UIRefreshControl()
refreshControl.tintColor = tintColor
refreshControl.addAction(forEvent: .valueChanged, closure: {
DispatchQueue.main.asyncAfter(deadline: .now() + JDDurationConstants.shortAnimationDuration) {
completion()
}
})
self.refreshControl = refreshControl
}
}
extension UIRefreshControl {
func beginRefreshingManually() {
DispatchQueue.main.async { [weak self] in
guard let scrollView = UIApplication.shared.topViewController()?.getScrollView() else { return }
let constant = UIApplication.shared.getTopHeightOfSafeArea() +
(UIApplication.shared.topViewController()?.navigationController?.navigationBar.bounds.height ?? 0) +
(self?.frame.height ?? 0)
scrollView.setContentOffset(CGPoint(x: 0, y: -constant), animated: true)
self?.sendActions(for: .valueChanged)
self?.beginRefreshing()
}
}
}

您是否尝试在viewDidLoad中手动调用beginRefreshingManuall方法?

override func viewDidLoad() {
super.viewDidLoad()
//it will react as if you were being renewed with your hand
yourUIRefreshControl.beginRefreshingManually()
}

最新更新