2010-12-16 5 views
1

dans mon délégué app j'ai ceci:problème avec NavigationBar et UIImagePickerController

@implementation UINavigationBar (CustomImage) 
- (void)drawRect:(CGRect)rect 
{ 
UIImage *image = [UIImage imageNamed: @"HeaderViewBG.png"]; 
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 
@end 

pour définir une image d'arrière-plan navigationbar. Mais je dois utiliser un UIImagePickerController, donc j'ai ce code:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 1) { 
     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsEditing = YES; 
    picker.navigationBar.barStyle = UIBarStyleDefault; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     [self presentModalViewController:picker animated:YES]; 
     [picker release]; 
    } 
} 

Le résultat est:

alt text

Je veux le style par défaut UIImagePickerController barre de navigation. Je ne veux pas l'image de fond utilisée dans l'application, je veux la barre de navigation par défaut.

Comment puis-je résoudre ce problème?

Merci beaucoup.

+0

DId vous résolvez ce problème? – CVertex

+0

bien, et vous? Je suis aussi intrigué de savoir. –

Répondre

0

Supprimez le code de la barre de navigation et supprimez l'instruction où vous appelez dessinez cette fonction.

il supprime la barre de navigation personnalisée, puis vous obtenez la barre de navigation par défaut.

0
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    if ([navigationController isKindOfClass:[UIImagePickerController class]]) { 
     if ([[UIDevice currentDevice] systemVersion].floatValue >= 8.0) { 
      [viewController.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navbar1"]]]; 
     } else { 
      [viewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar2"] forBarMetrics:UIBarMetricsDefault]; 
     } 
    viewController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; 
    titleLabel.textColor = [UIColor whiteColor]; 
    titleLabel.textAlignment = NSTextAlignmentCenter; 
    titleLabel.font = [UIFont boldSystemFontOfSize:18.0f]; 
    titleLabel.text = @"photos"; 
    [viewController.navigationItem setTitleView:titleLabel]; 
    viewController.edgesForExtendedLayout = UIRectEdgeNone; 
    } 
} 
Questions connexes