Can I change the size of UIActivityIndicator?
Solution 1
The size is fixed by the style. It's a standardized interface element so the API doesn't like to fiddle with it.
However, you probably could do a scaling transform on it. Not sure how that would affect it visually, however.
Just from a UI design perspective, its usually better to leave these common standardized elements alone. User have been taught that certain elements appear in a certain size and that they mean specific things. Altering the standard appearance alters the interface grammar and confuses the user.
Solution 2
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.
Solution 3
Swift 3.0 & Swift 4.0
self.activityIndi.transform = CGAffineTransform(scaleX: 3, y: 3)
Solution 4
It is possible to resize UIActivityIndicator.
CGAffineTransform transform = CGAffineTransformMakeScale(1.5f, 1.5f);
activityIndicator.transform = transform;
Original size is 1.0f. Now you increase and reduce size accordingly.
Solution 5
Swift3
var activityIndicator = UIActivityIndicatorView()
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let transform: CGAffineTransform = CGAffineTransform(scaleX: 1.5, y: 1.5)
activityIndicator.transform = transform
activityIndicator.center = self.view.center
activityIndicator.startAnimating()
self.view.addSubview(activityIndicator)
Related videos on Youtube
wolverine
Updated on January 13, 2022Comments
-
wolverine over 2 years
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;
-
jose920405 over 9 yearsCheck This stackoverflow.com/questions/8585715/…
-
-
hokkuk about 11 yearsand the activity indicators are much too small on the iPad with having one in the middle of a webView...
-
prewett over 10 yearsThis seems to scale up the pixels, so not acceptable for large amounts, unfortunately.
-
Ky - almost 9 yearsThat's great in certain contexts. However, what if this is in a splash screen, and all you see is the logo and maybe this teensy little spinner in the middle of the screen, it looks a bit silly. I can't believe Apple thinks one-size-fits-all is even a concept in UI elements.
-
Rohit Funde over 7 years
let transform = CGAffineTransformMakeScale(1.5, 1.5)
activityIndicator.transform = transform
-
meaning-matters over 7 years@BenLeggiero You're not talking about
UIActivityIndicatorViewStyleWhiteLarge
, but about the small size instead, right? Because I think that thisLarge
version has a nice size even on an empty screen. -
rockhammer over 7 years
.whiteLarge
does it! thx! I also setUIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
andactivityIndicator.backgroundColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.38)
. On 6+/7+ screens the default one is just too tiny -
Gandalf458 almost 7 yearsIt will look blurry if you do a scaling transform to increase the size.
-
nocdib almost 6 yearsExactly what I needed. This should be the top answer.
-
Michele Dall'Agata almost 6 yearsI love the one line solutions for simple matters! Now the only issue is how to anti alias it. At twice the size it looks a bit rough on Apple TV
-
Harshil Kotecha almost 6 years@MicheleDall'Agata still there is no any native solution for the good quality graphics progress bar in iOS if you want to make custom than it is good but i suggest to use native bcoz of app size and app performance
-
Michele Dall'Agata almost 6 years@HarshilKotecha Actually I have found out later that (at least for tvOS) in the IB there is a style for the activity gear that's called "Large White". That one has twice the proportions of the normal one, which is what I aimed to. The regulars are too small, good maybe for a single cell.