Set Color of UIActivityIndicatorView of a UIRefreshControl?

electronix384128 picture electronix384128 · May 11, 2013 · Viewed 8.8k times · Source

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?

Answer

Mike picture Mike · May 15, 2013

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;
        }
    }
}