Reputation: 2982
I am trying to add a UIActivityIndicator to my custom view (programmatically). I am using the following code. But I dont see anything on the screen. Any idea why ?
Thanks.
UIActivityIndicatorView *activityIndicator=[[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(75, 395, 200, 200)] autorelease];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.center=self.view.center;
[self.view addSubview:activityIndicator];
Upvotes: 0
Views: 1128
Reputation: 170859
UIActivityIndicator
has its hidesWhenStopped
property equal to YES
by default - that is it is hidden if you do not start animating it. So to make it appear on the screen try one of the following (whichever is more suitable for you):
hidesWhenStopped
property to NO
-startAnimating
method)Upvotes: 11
Reputation: 896
Another reason is maybe because you're not set the activity indicator position correctly. From what I see, you want to place the activity indicator to the center of it's parent view. But to do that, you must do something like activityIndicator.center = CGPointMake(self.view.frame.origin.x + self.view.bounds.size.width / 2.0, self.view.frame.origin.y + self.view.bounds.size.height / 2.0);
Upvotes: 2