如何更改UIImagePickerController导航栏上的button颜色?

我已经设法改变navigation bar的颜色,但button的颜色仍然是黑色的。 有没有办法改变button的颜色? 见下图。

更新 :抱歉,由于版权问题,必须删除图像。

没有你的自定义图像是不可能的。

但您应该在创build导航控制器后立即更改色调颜色:

  UIImagePickerController *pickerImg = [[UIImagePickerController alloc] init]; pickerImg.navigationBar.barStyle = UIBarStyleBlackOpaque; // Or whatever style. // or pickerImg.navigationBar.tintColor = [UIColor whateverColor]; 

你可以隐藏naviagtion栏,并使用imageview创build一个自定义的导航栏,并在其上放置2个button。通过这样做,您可以根据需要更改button的图像/颜色以及图像视图。

用于隐藏导航栏:

  self.navigationController.navigationBarHidden=YES; 

然后在XIB中:创build一个44高度的视图,将imageview放在它上面,并放置2个button和1个标签。

希望这会解决你的问题。

@Ankit您可以尝试从导航栏中获取子视图,然后设置所需的颜色。 我使用这种方法来设置search栏上取消button的颜色。 取消button的大小是48 * 30,您可以使用子视图数组来设置所需的颜色。 我不确定,但这可能会完成这项工作。 以下是我用来在search栏上设置取消button颜色的代码。

 NSArray *arrySearchSubviews=[searchBarFrnds subviews]; for (UIButton *btn in arrySearchSubviews) { CGRect rect=btn.frame; NSLog(@"width %f",rect.size.width); NSLog(@"height %f",rect.size.height); if (rect.size.width==48 ) { [btn setTintColor:[UIColor colorWithRed:0 green:0.403f blue:0.4f alpha:1.0f]]; } } 

如果要影响所有视图(如希望更改的视图)中出现的button的颜色,则只需使用以下内容:

 UIBarButtonItem *searchBarButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]; [searchBarButton setTintColor:[UIColor colorWithRed:138.0/255.0 green:183.0/255.0 blue:64.0/255.0 alpha:1.0]]; 
 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([navigationController isKindOfClass:[UIImagePickerController class]]) { if ([[UIDevice currentDevice] systemVersion].floatValue >= 8.0) { [viewController.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navbar1"]]]; } else { [viewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar2"] forBarMetrics:UIBarMetricsDefault]; } viewController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; titleLabel.textColor = [UIColor whiteColor]; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.font = [UIFont boldSystemFontOfSize:18.0f]; titleLabel.text = @"photos"; [viewController.navigationItem setTitleView:titleLabel]; viewController.edgesForExtendedLayout = UIRectEdgeNone; } } 

您可以使用iOS 5及更高版本中的新UIAppearance API来实现所需的自定义设置。 本教程主要向您展示如何。

你必须为你的BarButtonItem定义一个UIButtonTypeCustombutton。

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIBarButtonItem *yourBarButton = [[UIBarButtonItem alloc] initWithCustomView:button]; 

欲了解更多信息,看看这个职位: UIBarButtonItem与颜色?

我希望它会帮助你!

步骤1:

 UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; [self presentViewController:picker animated:YES completion:NULL]; 

第2步:

 /* Status bar color */ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; /* Left button */ navigationController.navigationBar.tintColor = [UIColor blackColor]; /* Right button color */ navigationController.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor blackColor]; 

如果您不介意在整个应用程序中使用相同的样式,请使用@Bournebuild议的外观:

  let font = UIFont(name:"Montserrat-Bold", size:16)! let attributes: LTDictStrObj = [ NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: font, ] UIBarButtonItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal) 

如果您使用像我这样的白色,也可以更改导航栏的背景颜色:

  picker.navigationBar.barTintColor = .redColor() 

使用UIAppearance的一个class轮:

 [[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]] setTintColor:[UIColor redColor]];