user3298872
user3298872

Reputation: 231

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.

Upvotes: 1

Views: 583

Answers (1)

user1445205
user1445205

Reputation:

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.

Upvotes: 1

Related Questions