Set color UIActivityIndicatorView UIRefreshControl?

Is there a way to set the color of the activity indicator (possibly UIActivityIndicatorView ) of the UIRefreshControl ?

I managed to set the color of the rubber and 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 the โ€œrubberโ€ blue and the activity indicator white, is this possible?

+4
source share
3 answers

This is not officially supported, but if you want to risk future iOS changes that violate your code, you can try the following:

After creating an ayoy answer, I built a subclass of UIRefreshControl that sets the color of the ActivityIndicator to beginRefresing . This should be better than it can be done, as you can call it code instead of the user invoking the animation.

 @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; } } } 
+3
source

Well, you can technically do this, but this is not supported. You better follow Daveโ€™s suggestion or read if you insist.

If you examine subviews from UIRefreshControl , then it turns out that it contains one subview, of the _UIRefreshControlDefaultContentView class.

If you then check the subviews of this content in an updated state, it contains the following:

  • UILabel
  • UIActivityIndicatorView
  • UIImageView
  • UIImageView

So, technically, in your callback to the UIControlEventValueChanged event UIControlEventValueChanged you can do something like this:

 UIActivityIndicatorView *spinner = [[[[self.refreshControl subviews] lastObject] subviews] objectAtIndex:1]; spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; 

And it will work. It also does not violate the Application Validation Guide, since it does not use a private API (viewing subheadings of a presentation and playing with them using a public API is legal). But keep in mind that the internal implementation of UIRefreshControl can change at any time, and your code may not work or even crash in later versions of iOS.

+2
source

No, It is Immpossible. You will need to specify an improvement request to ask Apple to implement this.

+1
source

Source: https://habr.com/ru/post/1480286/


All Articles