Ahsan
Ahsan

Reputation: 2982

problem with adding UIActivityIndicator to the view !

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

Answers (2)

Vladimir
Vladimir

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):

  1. set hidesWhenStopped property to NO
  2. start animating it (using -startAnimating method)
  3. comment "activityIndicator.center=self.view.center;"

Upvotes: 11

cpprulez
cpprulez

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

Related Questions