ContactsSuggestionTextField

iOS Swift 4+ Carthage compatible License: MIT

A simple and adaptive UITextField subclass which attaches a contact picker to the textfield’s input accessory view for seamless contact access.

Keyboard Appearance - Dark / Light

Note: This Library uses Contacts.framework and hence one needs to provide NSContactsUsageDescription in the app’s Info.plist specifying an appropriate reason.

Features

  • Integrated Contacts Access and Permission Handling.
  • Choose between phone number and e-mail address.
  • Adaptable UI.

Usage

To start using the component add it to your project using Carthage or manually as per the Installation section.

The UI component can be used via the ContactsSuggestionTextField class. This control can be used very similar to UITextField - both from Interface Builder, or from code.

To create an instance of the class, use Interface builder, or do it from code. This example will create a field which shows a short name and email address of a contact:

let textField = ContactsSuggestionTextField(frame: CGRect(x: 10, y: 10, width: 200, height: 45))

/// customize the textfield.
/// For Interface Builder, an IBOutlet can be created and the customization can be done as illustrated below.
textField.customize = { builder in
    builder.contactNameStyle = .short
    builder.contactType = .emailAddress
}
self.view.addSubview(textField)

Do something when the user selects a contact like the following:

tf.contactSelectedHandler = { [weak self] contact: String in
    // do something with contact
}

Installation

CocoaPods

The control is available through CocoaPods. CocoaPods can be installed using Ruby gems:

$ gem install cocoapods

Then simply add ContactsSuggestionTextField to your Podfile:

pod 'ContactsSuggestionTextField', '~> 0.0.3'

Lastly, let CocoaPods fetch the latest version of the component by running:

$ pod update

Carthage

The component supports Carthage. Start by making sure you have the latest version of Carthage installed. Using Homebrew run this:

$ brew update
$ brew install carthage

Then add ContactsSuggestionTextField to your Cartfile:

github "paulsumit1993/ContactsSuggestionTextField"

Finally, add the framework to the Xcode project of your App. Link the framework to your App and copy it to the App’s Frameworks directory via the “Build Phases” section.

Manual

You can download the latest files from our Releases page. After doing so, copy the files in the ContactsSuggestionTextField folder to your project.

Contributing

We welcome all contributions. Just open an issue or submit pull requests, and we will take it forward.