UIRefreshControl hue color does not match specified color

The update color does not match the color of the hue and it looks different, I tried to change tintAdjustmentMode, but the result is the same

Just to notice, the spinner and text color should be 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]}]; 

enter image description here

+7
source share
2 answers

UIRefreshControl is a buggy class. I noticed that placing tvc.refreshControl.tintColor = [UIColor colorWithHex:0x2C76BE]; inside an animation block (even zero duration) will produce the expected results. So I tested to make this disgusting “hack”: dispatch_async(mainQueue, <#set tintColor#>); , and this also gives the correct result. There may also be a dependency on refreshcontrol on the call time of -beginRefreshing or -endRefreshing .

Since I was so annoyed by the UIRefreshControl error and limited use only in the UITableViewController, I created a fully customizable one of mine that can be used with any type of UIScrollView (UICollectionView, UITableView). Note that I created this before the UICollectionViewFlowLayout supports sticky headers such as tableView, so my refreshcontrol does not work well when this option is enabled. Feel free to submit a correction;).

You can find it here https://github.com/Joride/JRTRefreshControl (if it falls under the “shameless offer to connect”, I will remove this link, but I think it has to do with the question.

0
source

I had a similar problem with UIRefreshControl, which did not display color correctly when loading the view, and I call beginRefreshing (). If the user pulls for an update, the control correctly displays the tintColor I specified.

First, a subclass of update management. Then override the didMoveToWindow method in the subclass. The following code finds an animated element to create a counter and sets its background color.

This code uses the UIView extension to return all subviews of the view (I used John Willis' answer from Swift: iterate over all subviews recursively to find a specific class and add to the 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 } } 

The spinner has a CAReplicatorLayer, the view of which contains one subview. This subview is just a rectangle that implements a graphic element for a counter. This is the graphic element that you are coloring.

0
source

All Articles