0

我已經做了sublass從UINavigationController ......這裏面I類設置的外觀如下:套裝的外觀恢復爲默認

UIImage *navBackgroundImage = [UIImage imageNamed:@"nav_bg"]; 
    [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault]; 

    [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: 
                  [UIColor whiteColor], UITextAttributeTextColor, 
                  [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],UITextAttributeTextShadowColor, 
                  [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], 
                  UITextAttributeTextShadowOffset, 
                  [UIFont fontWithName:@"Yellowtail" size:30.0], UITextAttributeFont, 
                  [UIColor whiteColor], UITextAttributeTextColor, nil]]; 
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.0f green:170/255.0f blue:130/255.0f alpha:1.0f]]; 

    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:0.0f green:170/255.0f blue:130/255.0f alpha:1.0f]]; 
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]]; 

現在,在我的應用程序時,我想拍照就呈現我的UIImagePicker,但導航欄有像我的自定義導航控制器的導航欄相同的外觀和取消按鈕不起作用...

所以我的問題:我如何使用默認的iOS風格的圖像選擇器和其餘的我的自定義樣式?

回答

1

的研究小時後我已經解決了這個問題......解決方案很簡單:

UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 

/* reset the style to the default one */ 
[picker.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 
[picker.navigationBar setTitleTextAttributes:nil]; 
[picker.navigationBar setBarTintColor:nil]; 

[self presentViewController:picker animated:YES completion:nil]; 

這裏有人有同樣的問題:Custom nav bar with UIImagePickerControl

0

由於你的答案最早出現在谷歌的時候我搜索這個問題,我更喜歡張貼正確的答案,而不是接受的答案。

This SO post正確處理問題。 UIAppearance具有用於精細UI定製的方法:appearanceWhenContainedIn:

如,例如:

[[UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil] setBackButtonBackgroundImage:[UIImage imageNamed:@"blank-button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];