Domanda

avere un po 'problema di progettazione, dopo aver eseguito l'aggiornamento a iOS 5 e Xcode 4.2

Ecco come il mio vista sembrava in iOS 4:

1 http://casperslynge.dk/1

E questo è come sembra in iOS 5:

2 http://casperslynge.dk/2

Nel mio delegato di navigazione ho il seguente metodo per disegnare l ' "immagine" nella parte superiore:

- (void)drawRect:(CGRect)rect {
    UIImage *image;
    if(self.barStyle == UIBarStyleDefault){
        image = [UIImage imageNamed: @"topbar_base.png"];
    }
    else{
        image = [UIImage imageNamed: @"nyhedsbar_base.png"];    
    }
    [image drawInRect:CGRectMake(-1, -1, self.frame.size.width+3, self.frame.size.height+3)];
}

E dentro il mio controller ho impostato il seguente:

self.navigationBarStyle = UIBarStyleBlack;

Come mai non funziona in iOS 5?

Grazie

È stato utile?

Soluzione

Under iOS5, you need to use UIAppearance. Have a look at that. Here's an example for using it conditionally so that you can continue to support iOS4:

// iOS5-only to customize the nav bar appearance
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
    UIImage *img = [UIImage imageNamed: @"NavBarBackground.png"];
    [[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
}

As you can see, this sets a custom background image for all UINavigationBars. There are lots of things you can do with UIAppearance. You'll want to keep any custom stuff you're currently doing in drawRect: since pre-iOS4 devices will still use that and not the new UIAppearance code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top