gpt4 book ai didi

swift - UIRefreshControl 的tintColor 无法初始设置

转载 作者:行者123 更新时间:2023-11-30 10:31:45 33 4
gpt4 key购买 nike

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

问题是我想将refreshControl的颜色更改为.white,例如,我在每个 View Controller 的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()
}

关于swift - UIRefreshControl 的tintColor 无法初始设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59033460/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com