Can I change the size of UIActivityIndicator?

wolverine picture wolverine · Apr 14, 2010 · Viewed 75.8k times · Source

Whatever size i give to it while allocation, it shows fixed size only. Is it possible to increase it?

Code:

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:
                     CGRectMake(142.00, 212.00, 80.0, 80.0)];
[[self view] addSubview:activityIndicator];
[activityIndicator sizeToFit];
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                      UIViewAutoresizingFlexibleRightMargin |
                                      UIViewAutoresizingFlexibleTopMargin |
                                      UIViewAutoresizingFlexibleBottomMargin);
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

Answer

Andrew Vilcsak picture Andrew Vilcsak · Mar 1, 2012

The following will create an activity indicator 15px wide:

#import <QuartzCore/QuartzCore.h>

...

UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
activityIndicator.transform = CGAffineTransformMakeScale(0.75, 0.75);
[self addSubview:activityIndicator];

While I understand the sentiment of TechZen's answer, I don't think adjusting the size of a UIActivityIndicator by a relatively small amount is really a violation of Apple's standardized interface idioms - whether an activity indicator is 20px or 15px won't change a user's interpretation of what's going on.