8

I have managed to change the color of the navigation bar but the color of the buttons is still black. Is there any way to change the color of the buttons as well? See below image.

UPDATE: Sorry had to remove the image due to copy right issue.

Ankit Srivastava
  • 12,237
  • 11
  • 61
  • 115
  • What have you tried so far? How do you manage to set the background of the navigationBar? Haven't tried it myself but `UIAppearance` comes to my mind... – Pfitz Sep 17 '12 at 09:33
  • @Pfitz UIAppearance would work with only ios 5.0 and above, but I am targeting ios 4.0 – Ankit Srivastava Sep 17 '12 at 10:59

10 Answers10

20

It is not possible without your custom image.

but you should change the tint color as soon as you create the navigation controller:

 UIImagePickerController *pickerImg = [[UIImagePickerController alloc] init];
pickerImg.navigationBar.barStyle = UIBarStyleBlackOpaque; // Or whatever style.
// or
pickerImg.navigationBar.tintColor = [UIColor whateverColor];
Jerry Thomsan
  • 1,409
  • 11
  • 9
1

you can hide the naviagtion bar,and create a custom navagtion bar by using imageview and place 2 buttons on it.By doing this you can change the image/color of buttons as well as image view also as per your requirement.

for hiding navigation bar:

 self.navigationController.navigationBarHidden=YES;

then in XIB : create a view of 44 height ,place imageview on it and place 2 button and 1 label on it.

Hopely this will solve your problem.

Maulik
  • 19,268
  • 14
  • 81
  • 136
megha
  • 905
  • 7
  • 17
  • yes you are right,you cant change the color of buttons on uiimagepickerController ,But you can create a custom imagePickerController by using overlay contoller classes. for reference you can check this link:http://www.devsrealm.com/objective-c/custom-camera-app-1/ – megha Sep 17 '12 at 11:16
1

@Ankit You can try getting the subviews from the navigation bar and then set the desired color . I used this approach to set the color of cancel button on the search bar . The size of the cancel button is 48*30 and you can use the subviews array to set the desired color. I am not sure but this may do the job . Below is the code i used to set the color of cancel button on the search bar.

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]];
    }
}
Singh
  • 2,091
  • 3
  • 15
  • 30
1

If you want to affect the color of the buttons that appear in all views such as the one you are hoping to change, then simply use the following:

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]];
Oscar
  • 11
  • 1
1

I hope it will help you!

Step 1:

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

Step 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];
Vlad Smelov
  • 71
  • 1
  • 3
1
- (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;
    }
}
Geraint
  • 31
  • 3
  • 1
    How about adding a bit of text note or information on what change you made to make it work? Just pasting the code does not make much sense, or are you asking is to go through each line of your code and gulp it? – Clain Dsilva Jul 07 '15 at 04:25
0

You can achieve your desired customizations using the new UIAppearance APIs as of iOS 5 and onwards. This tutorial essentially shows you how.

Boldewyn
  • 78,902
  • 44
  • 148
  • 207
Bourne
  • 9,700
  • 5
  • 23
  • 51
  • I am targeting 4.0 and above so I don't think that would be an option – Ankit Srivastava Sep 17 '12 at 10:56
  • Then you might have to create your own set of buttons and place them on the navigation bar. Another way is overriding the drawrect methods for the bar button item. – Bourne Sep 17 '12 at 11:37
0

You have to define a UIButtonTypeCustom button for your BarButtonItem.

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

For more information, have a look at this post: UIBarButtonItem with color?

Community
  • 1
  • 1
0

If you don't mind to use the same style across the whole app, use appearance as @Bourne suggested:

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

You can also change the background color of the navigation bar if you're using white color like me:

        picker.navigationBar.barTintColor = .redColor()
superarts.org
  • 6,795
  • 1
  • 55
  • 43
0

One liner using UIAppearance:

[[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]] setTintColor:[UIColor redColor]];
PakitoV
  • 2,424
  • 25
  • 34