将UIImagePickerController的外观设置为默认值

时间:2014-11-05 01:21:52

标签: ios objective-c uinavigationcontroller uiimagepickercontroller

我已经从UINavigationController创建了一个子类...在这个类中我将外观设置为以下内容:

    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,但导航栏具有与我的自定义导航控制器相同的外观'导航栏和CANCEL按钮不起作用......

所以我的问题:我如何使用默认的iOS样式用于图像选择器,我的自定义样式用于其余部分?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

由于当我搜索此问题时,您的答案首先出现在Google中,我更愿意发布正确的答案而不是接受的答案。

This SO post正确对待问题。 UIAppearance有一个用于精细UI自定义的方法:appearanceWhenContainedIn:

例如:

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