4

Je Tyring de personnaliser les couleurs un peu dans un ABPeoplePickerNavigationController ci-dessous est mon code complet:Changement tintColor de UISearchBar à l'intérieur ABPeoplePickerNavigationController

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]; 
objPeoplePicker.topViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0]; 
[self presentModalViewController:objPeoplePicker animated:YES]; 

Personnalisation du NavigationBar tintColor, cela fonctionne en ligne:

objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0]; 

Mais, je voudrais également personnaliser la teinteCouleur de la barre de recherche:

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

Cette ligne ne fonctionne pas. Je pense que je peux référencer le mauvais searchBar .... pouvez-vous me diriger dans la bonne direction?

Répondre

3

Je viens de rencontrer le même problème. Changer la couleur de NavBar est facile. Changer la couleur de UISearchBar cependant pas tellement. D'abord ce que j'ai fait était de vérifier

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

Les deux fois le searchDisplayController était nul. Ce que j'ai fini par faire était de traverser la hiérarchie de vue pour trouver la vue UISearchBar. Il y en a certainement un là. Donc, ceci est mon code final. Si quelqu'un a une meilleure solution, j'aimerais l'entendre.

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

Merci, même si ce fil est très ancien, il peut m'être utile plus tard. "Preciate le temps! –

+0

Une chose que j'ai remarquée par la suite est que si vous cliquez sur Groupes en haut à gauche du sélecteur et que vous revenez aux contacts, la couleur de la barre de recherche devient gris par défaut. – ribeto

+0

vraiment la grille Réponse: 0 –

1

Au lieu de changer la couleur ajouter une image à l'arrière-plan:

[mysearchBar setBackgroundImage:[UIImage imageNamed:@"<#Your image name#>"]]; 
1

Vous pouvez le faire en utilisant le proxy apparence UISearchBar maintenant:

UISearchBar* addressBookSearchBar = [UISearchBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil]; 
addressBookSearchBar.tintColor = [UIColor blackColor]; 
1

Pour iOS 7 + la meilleure façon est la manipulation du proxy d'apparence de la UISearchBar:

[[UISearchBar appearance] setBarTintColor:[UIColor blackColor]]; 
Questions connexes