直接代码,注释清晰
@interface RCZJJChangeImagePickerColorView : UIView
/**
改变图片类导航栏颜色
@param picker 略
@param barColor 导航栏颜色
*/
+ (void)colorSettingsWithPicker:(UIImagePickerController *)picker withBarColor:(UIColor *)barColor;
/**
改变图片类右侧取消按钮颜色
@param picker 略
@param titleColor 取消按钮的颜色
*/
+ (void)colorSettingsWithPicker:(UIImagePickerController *)picker cancelButtonTitleColor:(UIColor *)titleColor;
@end
+ (void)colorSettingsWithPicker:(UIImagePickerController *)picker withBarColor:(UIColor *)barColor {
picker.view.backgroundColor = [UIColor whiteColor];
if ([picker.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
picker.navigationBar.translucent = NO;
[picker.navigationBar setTintColor:[UIColor whiteColor]];
[picker.navigationBar setBarTintColor:barColor];
}
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
[picker.navigationBar setTitleTextAttributes:attrs];
}
+ (void)colorSettingsWithPicker:(UIImagePickerController *)picker cancelButtonTitleColor:(UIColor *)titleColor {
NSArray *itemsArray = picker.navigationBar.items;
for (UINavigationItem *nItm in itemsArray) {
NSArray *rArray = nItm.rightBarButtonItems;
for (UIBarButtonItem *barItem in rArray) {
SEL selector;
if (@available(iOS 11, *)) {
selector = NSSelectorFromString(@"tapCancel:");
} else {
selector = NSSelectorFromString(@"_handleImagePickerCancel:");
}
if (barItem.action == selector) {
barItem.tintColor = titleColor;
}
}
}
}
1.改变取消按钮颜色的方法的调用,写在跳转完成后的block里面:
/** 推出选择器 */
[self presentViewController:imagePickerController animated:YES completion:^{
[RCZJJChangeImagePickerColorView colorSettingsWithPicker:imagePickerController cancelButtonTitleColor:[UIColor whiteColor]];
}];
2.改变导航栏颜色的方法随意,如:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
[RCZJJChangeImagePickerColorView colorSettingsWithPicker:imagePickerController withBarColor:self.navigationController.navigationBar.barTintColor];