ios - 将 UIImagePickerController 的外观设置回默认值

标签 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,但导航栏的外观与我的自定义导航 Controller 的导航栏相同,并且“取消”按钮不起作用...

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

最佳答案

经过几个小时的研究,我已经解决了这个问题...解决方案非常简单:

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

关于ios - 将 UIImagePickerController 的外观设置回默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26748191/

相关文章:

ios - 导航 Controller 内的 pageviewcontroller 导致布局问题

ios - UITextField 验证

ios - NSDictionary dictionaryWithObject :key: crashes app

ios - 如何在不使用 UIWebView 的情况下获取网站的标题和描述?

iOS UIbutton奇怪的底部边缘

objective-c - 检测 NSString 是否包含...?

iOS:从导航堆栈中删除 View Controller

ios - 隐藏 UITableViewCell 中的行

ios - iPod 和 iPhone 之间的区别?在 APNS 中

ios - 如何弹出导航 Controller ?