Git Product home page Git Product logo

ctkflagphonenumber's Introduction

CTKFlagPhoneNumber

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

CI Status Version License Platform Language

Screenshot

Localization ๐ŸŒ

Country names are displayed according to the phone language

Example

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

Installation

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

pod "CTKFlagPhoneNumber"

Usage

You can instantiate it in storyboards or .xibs.

Programmatically:

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

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

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

// 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

Customization

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.
Bundle.FlagIcons = YOUR_FLAG_ICONS_BUNDLE

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

  • Localization
  • Country search
  • Placeholder
  • Exclude Countries
  • Any idea ?

Conception

This library is high inspired of MRCountryPicker library and use libPhoneNumber-iOS library. https://github.com/xtrinch/MRCountryPicker / https://github.com/iziz/libPhoneNumber-iOS

Author

grifas, [email protected]

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

License

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

ctkflagphonenumber's People

Contributors

grifas avatar fvolchyok avatar akilanarasu1994 avatar jmartinesp avatar

Watchers

James Cloos avatar Ahmer Baig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.