views:

366

answers:

2

New to all this Xcode stuff - I have a few UIButton's that links to movie & music files from my web site - they works fine, it's just that there's some lag time while it's loading the MoviePlayer where it seems as if nothing's happening.

I would like to set up an UIActivityIndicator - I can't sem to find a simple way to do it.

And if so, would I need one for each button?

Could you help? Thanks Carl

+1  A: 

You create an activity indicator and put it onscreen where you like - then you tell it to startAnimating when you request the media, and stopAnimating when you get a callback that the playback has begun.

You can do this programmatically or in IB, creating an IBOutlet so you can tell the indicator to start/stop.

Kendall Helmstetter Gelner
What would that code look like and where would it go?
+1  A: 

If you want to add an ActivityIndicator directly to your button, here's some code to do this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,40,40); // increase width value if you want to add text   
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];

UIActivityIndicatorView *actIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
actIndicator.tag = 123456;
[actIndicator startAnimating];
actIndicator.frame = CGRectMake(7, 7, 26, 26);
[button addSubview:actIndicator];
[actIndicator release];

This shows the activity view, but you could either hide it in the beginning or toggle the activity indicator by accessing the indicator via its tag.

Colins