开发者社区> 问答> 正文

请问怎么改变ABPeoplePickerNavigationController的UINavigationBar 颜色。

我用了ABAddressBookRef获取信息,用的还不错,不过我想改变
ABPeoplePickerNavigationController的UINavigationBar的颜色。能实现吗?怎么实现?

展开
收起
爵霸 2016-05-27 15:51:48 2547 0
1 条回答
写回答
取消 提交回答
  • 先设置颜色:

    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:@"> "];
    }
    2019-07-17 19:18:05
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载