2 garaster garaster 于 2012.10.15 10:38 提问

如何改变ABPeoplePickerNavigationController的UINavigationBar 颜色。

我用了ABAddressBookRef获取信息,用的还不错,不过我想改变
ABPeoplePickerNavigationControllerUINavigationBar的颜色。能实现吗?怎么实现?感谢帮忙。

2个回答

g989_1314125
g989_1314125   2012.10.15 16:07
已采纳

先设置颜色:

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:@"> "];
}
sch1111878
sch1111878 测试无效.不知道为什么
2 年多之前 回复
garaster
garaster 谢谢
大约 5 年之前 回复
lwq421336220
lwq421336220   2012.10.15 12:30

你可以设置一张你要的背景颜色的图片然后设置

[navigationController.navigationBar setBackgroundImage:
[UIImage imageNamed:@"navigationBar_bg.png"]forBarMetrics: UIBarMetricsDefault];

这个可以解决你的问题

sch1111878
sch1111878 不能用.
2 年多之前 回复
garaster
garaster 谢谢
大约 5 年之前 回复
suannai0314
suannai0314 代码部分可以用代码格式哦~
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!