BlueDolphin
BlueDolphin

Reputation: 9765

Background color for UIActivityIndicatorView

I am using UIActivityIndicatorView to showing user that there is something going on, let them wait. But UIActivityIndicatorView looks small, do not have background color, and not very obvious to the user. While in iPhone SDK's UIImagePickerController, it uses the similar mechanism, but with the black background as well as some text besides the indicator.

I am wondering whether there is any existing component to do that task, or I have to implement my own class to perform that task.

Any suggestion are highly welcome, thanks in advance.

Upvotes: 4

Views: 14904

Answers (3)

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

Try this simple method, Its working well for me....

UIActivityIndicatorView *activityIndicator= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
activityIndicator.layer.cornerRadius = 05;
activityIndicator.opaque = NO;
activityIndicator.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];
activityIndicator.center = self.view.center;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activityIndicator setColor:[UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]];
[self.view addSubview: activityIndicator];

Add following lines while load your view

//-- Add this line while processing to load your view
    [activityIndicator startAnimating];

//-- Add this line when after you view loaded
    [activityIndicator stopAnimating];

Upvotes: 5

BlueDolphin
BlueDolphin

Reputation: 9765

Seems I still have to create a separate view, because the indicator will be automatically enlarged if I enlarge the frame.

Thanks.

Upvotes: 2

leonho
leonho

Reputation: 3543

If you just want a different background color of your UIActivityIndictatorView, you could just send the setBackgroundColor message to the object, i.e.:

[activityIndicator setBackgroundColor:[UIColor blackColor]];

By the way, you can change the size of the indicator as well. just do setFrame or initWithFrame with a bigger rect. Remember UIActivityIndicatorView inherits from UIView so you get all the customization of UIView.

Upvotes: 13

Related Questions