简体   繁体   English

如何更改ABPeoplePickerNavigationController的UINavigationBar的颜色?

[英]How can I change color of UINavigationBar of ABPeoplePickerNavigationController?

I'm using ABAddressBookRef to get information of people for my Phone book. 我正在使用ABAddressBookRef来获取我的电话簿的人员信息。 It works properly, but I want to change color of UINavigationBar of ABPeoplePickerNavigationController . 它工作正常,但我想改变ABPeoplePickerNavigationControllerUINavigationBar的颜色。

Is this possible or not? 这可能吗? If possible, please tell me how to do it. 如果可能的话,请告诉我怎么做。

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 更改UISearchBar颜色

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:@"> "];
}

You can use appearance proxies to govern the appearance of the nav bar in the ABPeoplePickerNavigationController like so: 您可以使用外观代理来控制ABPeoplePickerNavigationController导航栏的外观,如下所示:

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]];

您可以尝试使用此代码更改UINavigationBar Color

    abPeoplePicker.navigationBar.tintColor=[UIColor redColor];
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 这将影响所有导航栏,但您设置了背景图像,而不是设置背景图像,但settintcolor设置仅设置条形图的颜色

You can try this code to change ABPeoplePickerNavigationController Color 您可以尝试使用此代码更改ABPeoplePickerNavigationController Color

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

or you can set RGB color 或者你可以设置RGB颜色

  objPicker.ViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.274 green:0.270 blue:0.268 alpha:0.8];

change color of UISearchBar of ABPeoplePickerNavigationController use like this way.... 改变ABPeoplePickerNavigationControllerUISearchBar的颜色就像这样使用....

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

Changing tintColor of UISearchBar inside ABPeoplePickerNavigationController 在ABPeoplePickerNavigationController中更改UISearchBar的tintColor

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:@"  "];
}
picker.topViewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何改变UINavigationBar的颜色? - How to change the color of UINavigationBar? iPhone:我无法更改 UINavigationBar 的颜色 - iPhone: I can't change the color of my UINavigationBar 如何更改UINavigationController的UINavigationBar? - How can I change the UINavigationBar of a UINavigationController? 如何更改ABPeoplePickerNavigationController的外观,以便查看电话号码类型(家庭,移动电话等) - How can I change the look of ABPeoplePickerNavigationController so that i can see phone number type (home,mobile etc) 如何更改UINavigationBar和按钮上的颜色? - How to change color of the UINavigationBar & buttons on it? 如何更改UInavigationBar附带的工具栏的颜色/样式? - how to change the color/style of the toolbar that comes with the UInavigationBar? 如何在UIViewController push上为UINavigationBar背景更改设置动画? - how can I animate the UINavigationBar background change on UIViewController push? 编辑UITableView时如何更改UINavigationBar中的按钮? - How can I change the buttons in a UINavigationBar when my UITableView is editing? 如何更改UINavigationBar按钮项目上的文本颜色 - How to change the text color on UINavigationBar button items 如何在iOS 8的UINavigationViewController中更改UINavigationBar的大小? - How can I change size of UINavigationBar in UINavigationViewController in iOS 8?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM