我已经从 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/