Reputation: 6733
Is there a way to set the color of the activity indicator (probably UIActivityIndicatorView
) of a UIRefreshControl
?
I was able to set the color of the 'rubber' and the indicator:
[_refreshControl setTintColor:[UIColor colorWithRed:0.0f/255.0f green:55.0f/255.0f blue:152.0f/255.0f alpha:1.0]];
But I want to have the 'rubber' blue and the activity indicator white, is this possible?
Upvotes: 4
Views: 9080
Reputation: 1995
This is not officially supported, but if you want to risk future iOS changes breaking your code you can try this:
Building off ayoy's answer, I built a subclass of UIRefreshControl, which sets the color of the ActivityIndicator in beginRefresing
. This should be a better place to put this, since you may call this in code instead of a user causing the animation to begin.
@implementation WhiteRefreshControl : UIRefreshControl
- (void)beginRefreshing
{
[super beginRefreshing];
NSArray *subviews = [[[self subviews] lastObject] subviews];
//Range check on subviews
if (subviews.count > 1)
{
id spinner = [subviews objectAtIndex:1];
//Class check on activity indicator
if ([spinner isKindOfClass:[UIActivityIndicatorView class]])
{
UIActivityIndicatorView *spinnerActivity = (UIActivityIndicatorView*)spinner;
spinnerActivity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
}
}
}
Upvotes: 3
Reputation: 3835
Well, you technically can do it, but it's not supported. You better follow Dave's suggestion, or read on if you insist.
If you investigate subviews of UIRefreshControl
it turns out that it contains one subview, of class _UIRefreshControlDefaultContentView
.
If you then check subviews of that content view in refreshing state, it contains the following:
UILabel
UIActivityIndicatorView
UIImageView
UIImageView
So technically in your callback to UIControlEventValueChanged
event you can do something like this:
UIActivityIndicatorView *spinner = [[[[self.refreshControl subviews] lastObject] subviews] objectAtIndex:1];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
And that would work. It also doesn't violate App Review Guidelines as it doesn't use private API (browsing subviews of a view and playing with them using public API is legal).
But keep in mind that the internal implementation of UIRefreshControl
can change anytime and your code may not work or even crash in later versions of iOS.
Upvotes: 2
Reputation: 243156
No, that's not possible. You'll need to file an enhancement request to ask Apple to implement this.
Upvotes: 1