4

I try to change the color of the ABPeoplePickerNavigationController navbar to my app colors. However no changes occur. Even when I try to hide it or at least change the status bar tint color, nothing happens. Why?

- (ABPeoplePickerNavigationController *)peoplePicker
{
    if(!_peoplePicker){
        _peoplePicker = [[ABPeoplePickerNavigationController alloc]init];
        _peoplePicker.peoplePickerDelegate = self;
        _peoplePicker.navigationBar.hidden = YES;
    }
    return _peoplePicker;
}

I lazy instantiate my navigation controller and the other method calls like dismiss view controller etc. work fine.

EDIT: This is my current code (for the bounty). No color changes happen like this:

- (ABPeoplePickerNavigationController *)peoplePicker
{
    if(!_peoplePicker){
        _peoplePicker = [[ABPeoplePickerNavigationController alloc]init];
        _peoplePicker.peoplePickerDelegate = self;
        _peoplePicker.navigationBar.tintColor = [UIColor blackColor];
    }
    return _peoplePicker;
}

- (IBAction)addressBookButtonClicked:(id)sender {
    [self presentViewController:self.peoplePicker animated:YES completion:nil];
}

Doesn't this work anymore on iOS8?

MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • Where's your attempt to change the colors? – rmaddy Sep 25 '14 at 16:00
  • Just showed an example with the hidden property that nothing works, not even hidden. Or navigationBar.tint neither.. – MichiZH Sep 25 '14 at 16:04
  • In my own app, simply setting the app navbar colors through the standard appearance proxy results in the navbar of `ABPeoplePickerNavigationController` appearing in the same app colors. Nothing special was needed. – rmaddy Sep 25 '14 at 16:12

4 Answers4

7

Actually, thanks to the comment above, I realized that an appearance proxy should work like so:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

Just put that in the viewDidLoad method of the View Controller from which you are instigating the ABPeoplePickerView. This will also work for MFMailerView as well. My code that I'm using to style my bars properly is:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
                                                                       fontWithName:@"Helvetica Neue" size:12], NSFontAttributeName,
                            [UIColor whiteColor], NSForegroundColorAttributeName, nil];

[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Keaton Burleson
  • 498
  • 3
  • 16
2
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    [[UIBarButtonItem appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarTintColor:[UIColor redColor]];
    [picker.navigationController.navigationBar setTranslucent:NO];

I call these methods before presenting the person picker not even in the viewdidload.

Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
1

the color issue: The navigationBar might not be loaded at the point when you are trying to access it. Have you tried to set the color properties after presenting the ABPeoplePickerNavigationController.

the hide issue: Normally you hide the NavigationBar by calling:

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;

on UINavigationController, in your case ABPeoplePickerNavigationController.

Cheers, Fabian

fabianfett
  • 709
  • 7
  • 15
1

You are using an instance variable (iVar) _peoplePicker, which belongs apparently to a property peoplePicker. Additionally, you have a method peoplePicker that returns an object of class ABPeoplePickerNavigationController *.
In your IBAction addressBookButtonClicked: you execute the instruction

[self presentViewController:self.peoplePicker animated:YES completion:nil];

This means you call your method peoplePicker, which checks the iVar _peoplePicker and sets it (e.g. the tint color) if it has a nil value.
But since you are using the iVar directly, i.e. _peoplePicker instead of self.peoplePicker, you do not use the setter method, but simply an assignment.
This means the retain count of the UIColor object that you create in [UIColor blackColor] with an retain count of 1 will not be increased by the instruction _peoplePicker.navigationBar.tintColor = [UIColor blackColor]; but will be put into an autorelease pool when it is returned by return _peoplePicker;. But the autoreleasepool will be drained when you app returns to the main event loop, and the UIColor object will be released.
So I suggest that you replace all assignments to _peoplePicker by assignments to self.peoplePicker. Then you are using the setter method, which will increase the retain count, and your UIColor object will survive.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
  • I've tried this but didn't work. Wouldn't make sense in my opinion anyway? Because my getter returns the iVar so the color should still be asigned shouldn't it? – MichiZH Oct 02 '14 at 14:08