views:

353

answers:

2

I'm wondering how Apple implemented the UINavigationItem that contains an activity indicator (see attached image below), above the title. Is this Apple's private API that allows to do that? If not, how can it be reproduced in an application.

http://img218.imageshack.us/img218/8819/img0133g.png

Thanks!

A: 

Try this:

// control state of system bar activity indicator

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

Trent
This toggles the network activity indicator in the device's status bar, which is quite a different thing.
Ole Begemann
A: 

I got the exact same rendering than your screenshot with this code:

 UIView                      *viewContainingSpinner;
    UIActivityIndicatorView     *activityIndicatorView;
    UIBarButtonItem             *activityButtonItem;
    UIBarButtonItem             *rightBarButtonItem;


    // Configuring the title and the prompt title of the navigation bar
    [self.navigationItem setTitle:@"MobileMe"];
    [self.navigationItem setPrompt:@"Vérification du compte MobileMe"];

    // We will create a UIBarButtonItem that has a custom view (viewContainingSpinner).
    // A subview of viewContainingSpinner will be a UIActivityIndicatorView (activityIndicatorView)
    // We need to have this "intermediate" view to position the spinner at the right position (the UIBarButtonItem ignores the origin and height of its custom view)
    viewContainingSpinner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 85)];
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    [viewContainingSpinner addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    [activityIndicatorView release];

    activityButtonItem = [[UIBarButtonItem alloc] initWithCustomView:viewContainingSpinner];
    self.navigationItem.leftBarButtonItem = activityButtonItem;
    [viewContainingSpinner release];
    [activityButtonItem release];

    // Finally, configuring the right button
    rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Enregistrer" style:UIBarButtonItemStylePlain target:nil action:nil];
    [rightBarButtonItem setEnabled:NO];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    [rightBarButtonItem release];



PS: In a real application, I would advise against having a localized string in code. The é of the word "Vérification" could cause you trouble. Have a look at the method NSLocalizedString.

Guillaume
Thanks a lot, it works perfectly!
legege