【问题标题】:UIRefreshControl tint color doesn't match given colorUIRefreshControl 色调颜色与给定颜色不匹配
【发布时间】:2015-12-21 01:31:10
【问题描述】:

刷新颜色和tint颜色不匹配,看起来不一样,我尝试改变tintAdjustmentMode但结果是一样的

请注意,微调器和文本颜色应为 0x2C76BE

tvc.refreshControl = [UIRefreshControl new];
tvc.refreshControl.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
tvc.refreshControl.tintColor = [UIColor colorWithHex:0x2C76BE];
tvc.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to query spectrum again" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x2C76BE]}];

【问题讨论】:

  • 0x2C76BE 看起来不是十六进制颜色。
  • 没关系,它的#2C76BE = 0x2C76BE
  • 这个运气好吗?我遇到了同样的问题:(

标签: ios uitableview cocoa-touch ios9 uirefreshcontrol


【解决方案1】:

UIRefreshControl 是一个有问题的类。我注意到将tvc.refreshControl.tintColor = [UIColor colorWithHex:0x2C76BE]; 放在动画块内(即使持续时间为零)也会产生预期的结果。所以我测试了这个可怕的“黑客”:dispatch_async(mainQueue, <#set tintColor#>);,这也给出了正确的结果。刷新控制也可能依赖于调用-beginRefreshing-endRefreshing 的时间。

因为 UIRefreshControl 的错误和只能在 UITableViewController 中使用的限制让我非常恼火,所以我创建了一个完全可自定义的我自己的,可用于任何类型的 UIScrollView(UICollectionView、UITableView)。请注意,我在 UICollectionViewFlowLayout 支持像 tableView 这样的粘性标题之前创建了它,所以当该选项打开时,我的 refreshcontrol 不能正常工作。随时提交修复;)。

你可以在这里找到它https://github.com/Joride/JRTRefreshControl(如果这属于“无耻的插入条款”,我会删除这个链接,但我认为它与问题有关。

【讨论】:

  • 我也遇到了同样的问题,我尝试了下面的dispatch_async(dispatch_get_main_queue(), ^(){ [[self refreshController] setTintColor:[UIColor colorFromHex:0xff8900]]; });,颜色还是不亮。 -beginRefreshing 方法不是我自己调用的,而是拉桌子的用户。在动画块中设置色调颜色似乎也没有效果。
【解决方案2】:

当视图加载时 UIRefreshControl 没有正确显示颜色并且我调用 beginRefreshing() 时,我遇到了类似的问题。如果用户拉动刷新,控件会正确显示我指定的 tintColor。

首先,子类化刷新控件。然后,覆盖子类中的 didMoveToWindow 方法。下面的代码查找动画元素以创建微调器并设置其背景颜色。

此代码使用 UIView 的扩展来返回所有视图的子视图(我使用 Jon Willis 来自 Swift: Recursively cycle through all subviews to find a specific class and append to an array 的答案)。

class CustomRefreshControl: UIRefreshControl {

    override func didMoveToWindow() {
        super.didMoveToWindow()
        if let l = getNestedSubviews().first(where: { $0.layer is CAReplicatorLayer }), l.subviews.count > 0 {
            l.subviews[0].backgroundColor = UIColor.orange //getNestedSubviews method is an extension of UIView as referenced above
        }
}

微调器有一个 CAReplicatorLayer,它的视图包含一个子视图。该子视图只是一个实现微调器的图形元素的矩形。就是你要着色的那个图形元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    相关资源
    最近更新 更多