문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

No, that's not possible. You'll need to file an enhancement request to ask Apple to implement this.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top