Search code examples
iosobjective-ccncontact

Customize ContactPicker UI in iOS 9


How do I customize the UI of the CNContactPickerViewController?

I want to alter the colors, fonts, and text - similar to how snapchat has done?

enter image description here

Currently - my CNContactPickerViewController looks exactly like Apple's native contacts app.


Solution

  • First get contacts from address book and pass them into an NSArray:

    CNContactStore *store = [[CNContactStore alloc] init];
    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
    
        NSMutableArray *contacts = [NSMutableArray array];
    
        NSError *fetchError;
        CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];
    
        BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) {
            [contacts addObject:contact];
        }];
        if (!success) {
            NSLog(@"error = %@", fetchError);
        }
    }];
    

    Then simply use the NSArray in a UITableView and from there you can customize the font, colors, etc.