6

ABAddressBookRef用来为我的电话簿获取人们的信息。它工作正常,但我想改变 的颜色UINavigationBarABPeoplePickerNavigationController

这可能吗?如果可能,请告诉我该怎么做。

4

8 回答 8

7

设置色调颜色,像这样....

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

更改 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:@"> "];
}
于 2012-10-09T06:49:31.263 回答
2

您可以使用外观代理来管理导航栏的外观,ABPeoplePickerNavigationController如下所示:

对于带有白条按钮项的红条:

[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarTintColor:[UIColor redColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:[UIColor whiteColor]];
于 2014-10-31T19:00:25.520 回答
1

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

    abPeoplePicker.navigationBar.tintColor=[UIColor redColor];
于 2012-10-09T06:53:55.020 回答
0
if ([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
    UIImage *backGroundImage = [[UIImage imageNamed:kNavigationBarBackGroundImage] stretchableImageWithLeftCapWidth:5 topCapHeight:5];
    [[UINavigationBar appearance] setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
}

这将影响所有导航栏,但您设置背景图像而不是设置背景图像,但 settintcolor 设置仅设置栏的颜色

于 2012-10-09T06:50:33.573 回答
0

您可以尝试使用此代码更改ABPeoplePickerNavigationController颜色

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

或者你可以设置RGB颜色

  objPicker.ViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.274 green:0.270 blue:0.268 alpha:0.8];
于 2012-10-09T07:20:09.240 回答
0

改变ABPeoplePickerNavigationController的UISearchBar的颜色 使用这样的方式....

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

在 ABPeoplePickerNavigationController 中更改 UISearchBar 的 tintColor

于 2012-10-09T07:49:36.920 回答
0

试试这个:

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:@"  "];
}
于 2012-10-09T09:23:18.853 回答
0
picker.topViewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
于 2014-07-30T08:24:30.787 回答