6

I'm using ABAddressBookRef to get information of people for my Phone book. It works properly, but I want to change color of UINavigationBar of ABPeoplePickerNavigationController.

Is this possible or not? If possible, please tell me how to do it.

Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92

8 Answers8

7

Set the tint color , like this way....

ABPeoplePickerNavigationController *objPeoplePicker = [[ABPeoplePickerNavigationController alloc] init];
[objPeoplePicker setPeoplePickerDelegate:self];
objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
[self presentModalViewController:objPeoplePicker animated:YES];

Changing the UISearchBar color

if( picker.searchDisplayController == nil ) 
  NSLog(@"searchDisplayController is nil");
if( picker.topViewController.searchDisplayController == nil ) 
  NSLog(@"topViewController.searchDisplayController is nil");


static BOOL foundSearchBar = NO;
- (void)findSearchBar:(UIView*)parent mark:(NSString*)mark {

  for( UIView* v in [parent subviews] ) {

    if( foundSearchBar ) return;

    NSLog(@"%@%@",mark,NSStringFromClass([v class]));

    if( [v isKindOfClass:[UISearchBar class]] ) {
      [(UISearchBar*)v  setTintColor:[UIColor blackColor]];
      foundSearchBar = YES;
      break;
    }
    [self findSearchBar:v mark:[mark stringByAppendingString:@"> "]];
  }
}

- (void)pickPerson:(BOOL)animated {
  foundSearchBar = NO;
  ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
  [[picker navigationBar] setTintColor:[UIColor blackColor]];

  picker.peoplePickerDelegate = self;
  picker.displayedProperties = [NSArray arrayWithObjects:
                  [NSNumber numberWithInt:kABPersonEmailProperty],
                  nil];

  [self presentModalViewController:picker animated:animated];
  [picker release];

  [self findSearchBar:[picker view] mark:@"> "];
}
Vikas S Singh
  • 1,748
  • 1
  • 14
  • 29
2

You can use appearance proxies to govern the appearance of the nav bar in the ABPeoplePickerNavigationController like so:

for a red bar with white bar button items:

[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarTintColor:[UIColor redColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:[UIColor whiteColor]];
Kevlar
  • 8,804
  • 9
  • 55
  • 81
1

You can try this code to change UINavigationBar Color

    abPeoplePicker.navigationBar.tintColor=[UIColor redColor];
Romit M.
  • 898
  • 11
  • 28
  • thanks for help me :) ...i wn as change color of UISearchBar of ABPeoplePickerNavigationController ... how can i do it ? –  Oct 09 '12 at 07:45
  • Go to this link. http://stackoverflow.com/questions/3618976/changing-tintcolor-of-uisearchbar-inside-abpeoplepickernavigationcontroller?answertab=active#tab-top – Romit M. Oct 09 '12 at 07:59
0
if ([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
    UIImage *backGroundImage = [[UIImage imageNamed:kNavigationBarBackGroundImage] stretchableImageWithLeftCapWidth:5 topCapHeight:5];
    [[UINavigationBar appearance] setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
}

This will affect all navigation bars but you set a backgroudn image rather then setting the background image but settintcolor sets only sets the color of the bars

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

You can try this code to change ABPeoplePickerNavigationController Color

objPicker.ViewController.navigationController.navigationBar.tintColor = [UIColor redColor];

or you can set RGB color

  objPicker.ViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.274 green:0.270 blue:0.268 alpha:0.8];
Bajaj
  • 859
  • 7
  • 17
  • thanks for help me :) ...i wn as change color of UISearchBar of ABPeoplePickerNavigationController ... how can i do it ? –  Oct 09 '12 at 07:41
0

change color of UISearchBar of ABPeoplePickerNavigationController use like this way....

objPicker.ViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];

Changing tintColor of UISearchBar inside ABPeoplePickerNavigationController

Community
  • 1
  • 1
Bajaj
  • 859
  • 7
  • 17
0

Try this:

static BOOL foundSearchBar = NO;
- (void)findSearchBar:(UIView*)parent mark:(NSString*)mark {

  for( UIView* v in [ subviews] ) {

    if( foundSearchBar ) return;

    NSLog(@"%@%@",mark,NSStringFromClass([v class]));

    if( [v isKindOfClass:[UISearchBar class]] ) {
      [(UISearchBar*)v  setTintColor:[UIColor blackColor]];
      foundSearchBar = YES;
      break;
    }
    [self findSearchBar:v mark:[mark stringByAppendingString:@"> "]];
  }
}

- (void)pickPerson:(BOOL)animated {
  foundSearchBar = NO;
  ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
  [[picker navigationBar] setTintColor:[UIColor blackColor]];

  picker.peoplePickerDelegate = self;
  picker.displayedProperties = [NSArray arrayWithObjects:
                  [NSNumber numberWithInt:kABPersonEmailProperty],
                  nil];

  [self presentModalViewController:picker animated:animated];
  [picker release];

  [self findSearchBar:[picker view] mark:@"  "];
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Bajaj
  • 859
  • 7
  • 17
0
picker.topViewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
Kevlar
  • 8,804
  • 9
  • 55
  • 81