2

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 .

pradeep
  • 3,005
  • 12
  • 42
  • 65
  • My solution.. working great: http://stackoverflow.com/questions/9568314/splash-screen-fade-with-activity-indicator-there-u-go – Maor Zohar Mar 05 '12 at 14:55

4 Answers4

3

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.

Kris Markel
  • 12,142
  • 3
  • 43
  • 40
  • Ok, that is, have to create a separate UIView class and NIB file and add the background image and UIActivityIndicator to it r8 ? – pradeep Oct 19 '10 at 04:37
  • 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. – Kris Markel Oct 19 '10 at 04:40
  • 1
    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 Oct 19 '10 at 04:42
1

Hi Pradeep I implement this code in monotouch for ios so this code is help ful to implement your logic

#region Splash Screen
public  void  ShowSplash(){
// get the Height & Width of device Screen
float mainSrcWidth = this.View.Bounds.Width; 
float mainSrcHeight = this.View.Bounds.Height;
splashScreen = new UIImageView (UIImage.FromFile ("Images/loadNew1536_2008.png"));
splashScreen.Frame = new RectangleF (0, 0, mainSrcWidth, mainSrcHeight);    
//Start the thread;
ThreadPool.QueueUserWorkItem (delegate {
Load ();
}
)
this.View.AddSubview(splashScreen);
}
#endregion


#region Load() splashscreen
private void Load ()
//Sleep for 3 seconds to simulate a long load.
Thread.Sleep (new TimeSpan (0, 0, 0, 3));
this.BeginInvokeOnMainThread (delegate {
splashScreen.RemoveFromSuperview ();
splashScreen = null;
});
}
#endregion

Call the ShowSplash() method from Appdelegate Class of FinishedLaunching Method

IMMORTAL
  • 2,707
  • 3
  • 21
  • 37
  • I am agree with Kris Markel but you can add the static images to it while loading app –  Sep 18 '12 at 06:09
1

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
  • 633
  • 1
  • 6
  • 6
0

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: How to use activity indicator view on iPhone?

Community
  • 1
  • 1
NWCoder
  • 5,296
  • 1
  • 26
  • 23