tags:

views:

51

answers:

3

How to add a UIActivityIndicator to a splash screen ?

Edit : I tried the following things

I created UIViewController Sub class called SplashViewController. and the code is as below, still the image is not persisting long enough .

A: 

UIActivityIndicators are UIViews and can be added like any other.

something like: [myView addSubview:mySpinner];

Or just drop one in your NIB.

here's another answer: http://stackoverflow.com/questions/593234/how-to-use-activity-indicator-view-on-iphone

NWCoder
I know how to use them, but how to add it to a splash screen ?
rajivpradeep
+1  A: 

If by "Splash Screen" you mean the image that is displayed when your app launches, the answer is that you can't.

What you can do is have an initial view that includes a background image that looks just like your launch image, and then add an activity indicator into that view. To the user, it will appear that the activity indicator is "part" of your launch image.

The trick is to load your initial nib as quickly as possible (keep it small and simple) so the static images transitions to a view you can manipulate right away.

Robot K
Ok, that is, have to create a separate UIView class and NIB file and add the background image and UIActivityIndicator to it r8 ?
rajivpradeep
Yes. For simplicity you may want to also create a separate view controller to manage it all for you as well. This is the view controller that your app would initially load.
Robot K
Exactly. I usually call the view something like LoadingViewController and make it look just like the Default.png image but with the loading indicator. You can call this view as a modal from your didFinishLaunchingWithOptions delegate method.
stitz
A: 

It depends on what you mean by a splash screen. If you mean the image that is first shown when the app is run, then we have a more tricky situation. This is just a static image (Default.png) so what you would then need to do is create a view that has your splash screen image as the background, add the activity indicator view on top of it, and then add that view directly from the app delegate. When whatever you're loading is done, you can get rid of this view and proceed with the rest of your program. Probably easier to do in a NIB, but here's an idea of it programmatically:

- (void)loadView;
{
    CGRect r = [UIScreen mainScreen].applicationFrame;
    UIView *activityView = [[[UIView alloc] initWithFrame:r] autorelease];
    self.view = activityView;

    activityView.backgroundColor = [UIColor blackColor];
    activityView.alpha = 0.5;

    UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]] autorelease];
    [activityView addSubview:imgView];

    CGRect wheelR = CGRectMake(r.size.width / 2 - 12, r.size.height / 2 - 12, 24, 24);
    UIActivityIndicatorView *activityWheel = [[UIActivityIndicatorView alloc] initWithFrame:wheelR];
    activityWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    activityWheel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                    UIViewAutoresizingFlexibleRightMargin |
                                    UIViewAutoresizingFlexibleTopMargin |
                                    UIViewAutoresizingFlexibleBottomMargin);
    [activityWheel startAnimating];
    [activityView addSubview:activityWheel];
}
simonista