LicenseApache License 2.0
Platformsios 8.0

CTKFlagPhoneNumber is a phone number textfield with a fancy country code picker.

CI Status


CTKFlagPhoneNumber CTKFlagPhoneNumber CTKFlagPhoneNumber

Localization 🌍

Country names are displayed according to the phone language


To run the example project, clone the repo, and run pod install from the Example directory first.


CTKFlagPhoneNumber is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "CTKFlagPhoneNumber"


You can instantiate it in storyboards or .xibs.


phoneNumberTextField = CTKFlagPhoneNumberTextField(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 16, height: 50))

// You can change the chosen flag
phoneNumberTextField.setFlag(for: "FR")

// You can change the phone number, which will update automatically the flag image
phoneNumberTextField.set(phoneNumber: "0600000001")

// By default, an example of a phone number according to the selected country is displayed in the placeholder. You can use your own placeholder:
phoneNumberTextField.hasPhoneNumberExample = false
phoneNumberTextField.placeholder = "Phone Number"

// You can also get the phone number in E.164 format, the country code and the raw phone number
print(phoneNumberTextField.getFormattedPhoneNumber()) // Output: +33600000001
print(phoneNumberTextField.getCountryPhoneCode()) // Output: +33
print(phoneNumberTextField.getRawPhoneNumber()) // Output: 600000001


FlagKit is used by default but you can customize the list with your own flag icons assets:

// Be sure to set it before initializing a CTKFlagPhoneNumber instance.

You can change the size of the flag:

phoneNumberTextField.flagSize = CGSize(width: 44, height: 44)

You can change the edge insets of the flag:

phoneNumberTextField.flagButtonEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10)

If you set the parentViewController, a search button appears in the picker inputAccessoryView to present a country search view controller:

phoneNumberTextField.parentViewController = self

You can customize the inputAccessoryView of the textfield:

phoneNumberTextField.textFieldInputAccessoryView = getCustomTextFieldInputAccessoryView(with: items)

You can also customize the flag button’s properties:

// This will freeze the flag.
// Only one particular country's phone numbers will be formatted and validated.
// You can set the country by setting the flag as shown earlier.
phoneNumberTextField.flagButton.isUserInteractionEnabled = false

Next Improvments

  • [x] Localization
  • [x] Country search
  • [x] Placeholder
  • [ ] Exclude Countries
  • [ ] Any idea ?


This library is high inspired of MRCountryPicker library and use libPhoneNumber-iOS library. /


grifas, [email protected]

Don’t hesitate to contact me or make a pull request to upgrade this library.


CTKFlagPhoneNumber is available under the Apache license. See the LICENSE file for more info.

Latest podspec

    "name": "CTKFlagPhoneNumber",
    "version": "0.5.0",
    "summary": "A formatted phone number UITextField with country flag picker.",
    "description": "CTKFlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code.",
    "homepage": "",
    "license": {
        "type": "Apache License 2.0",
        "file": "LICENSE"
    "authors": {
        "Auru00e9lien Grifasi": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.5.0"
    "platforms": {
        "ios": "8.0"
    "source_files": "CTKFlagPhoneNumber/**/*.swift",
    "resource_bundles": {
        "CTKFlagPhoneNumber": [
    "dependencies": {
        "libPhoneNumber-iOS": []

Pin It on Pinterest

Share This