UIRefreshControl 的 tintColor 无法初始设置

UIRefreshControl's tintColor can't be initially set

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

问题是我想将 refreshControl 的颜色更改为 .white,例如,我在每个 viewcontroller 的 viewDidLoad() 中调用 beginRefreshingManually() 函数,但初始颜色还是黑的。当尝试手动拉动刷新时,Refreshcontrol 变为 .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()
    }