RepositorySwift
NI

NikKovIos/NKVPhonePicker

An UITextField subclass to simplify country code's picking. Swift 5.0

142stars
43forks
9issues
1views


Platform Swift version License
CocoaPods CocoaPods

Preview


Installation

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

pod 'NKVPhonePicker'

Also you can try an example project with

pod try NKVPhonePicker

(don't forget to update your cocoapods master repo)

For swift 4.2 version use 011f7090e69a8446aadd21531e4b83da745cd2d4 in master branch.

If you're still using Swift 2.x - you can set (The development for swift_2.x is deprecated. Stale version still exists.)

pod 'NKVPhonePicker', :git => "https://github.com/NikKovIos/NKVPhonePicker.git", :branch => "Swift_2.x"

Usage

  1. Make your UITextField a class of NKVPhonePickerTextField
  2. Set its phonePickerDelegate to UIViewController in order to be able of presenting the CountriesViewController
  3. If any troubles - watch an example project.

Please, make an issue, if you need any features, or have bugs.

Example

topTextField.phonePickerDelegate = self
topTextField.favoriteCountriesLocaleIdentifiers = ["RU", "ER", "JM"]
topTextField.rightToLeftOrientation = true
topTextField.shouldScrollToSelectedCountry = false
topTextField.flagSize = CGSize(width: 30, height: 50)
topTextField.enablePlusPrefix = false

// Setting initial custom country
let country = Country.countryBy(countryCode: "EG")
topTextField.currentSelectedCountry = country

// Setting custom format pattern for some countries
topTextField.customPhoneFormats = ["RU" : "# ### ### ## ##",
                                   "GB": "## #### #########"]

// Adding programmatically
bottomTextField = NKVPhonePickerTextField(frame: CGRect(x: 0, y: 0, width: 0, height: 30))
bottomTextField.placeholder = "ex: 03123456"
bottomTextField.autocorrectionType = .no
bottomTextField.phonePickerDelegate = self
bottomTextField.keyboardType = .numberPad
bottomTextField.favoriteCountriesLocaleIdentifiers = ["LB"]
bottomTextField.layer.borderWidth = 1
bottomTextField.layer.borderColor = UIColor.white.cgColor
bottomTextField.layer.cornerRadius = 5
bottomTextField.font = UIFont.boldSystemFont(ofSize: 25)
bottomTextField.textColor = UIColor.white
bottomTextField.textFieldTextInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
bottomTextField.translatesAutoresizingMaskIntoConstraints = false

// prefilling
let source = NKVSource(countryCode: "ru")
bottomTextField.setCurrentCountryInitially = false
bottomTextField.preFillText(source: source, number: 7999432423)

Note: 'In this library used the TextFieldPatternFormat lib by Vojta Stavik'

TODO:

  • Add example
  • Max numbers count var (can do with custom pattern)
  • Patterns for each country

Checkout my other works

Similar Projects

Discover other similar projects and AI models.

RepositorySwift
HeroTransitions/Hero

Elegant transition library for iOS & tvOS

22.5k
Jan 23, 2025
Repository
dkhamsing/open-source-ios-apps

:iphone: Collaborative List of Open-Source iOS Apps

53.6k
Nov 30, 2026
RepositorySwift
permissionlesstech/bitchat

bluetooth mesh chat, IRC vibes

37.2k
Nov 27, 2026
RepositorySwift
airbnb/lottie-ios

An iOS library to natively render After Effects vector animations

27.0k
Nov 24, 2026
RepositorySwift
ReactiveX/RxSwift

Reactive Programming in Swift

24.6k
Nov 13, 2026
RepositorySwift
onevcat/Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.

24.4k
Nov 28, 2026
RepositorySwift
CodeEditApp/CodeEdit

📝 CodeEdit App for macOS – Elevate your code editing experience. Open source, free forever.

23.1k
Oct 17, 2026
Repository
xitu/gold-miner

🥇掘金翻译计划,可能是世界最大最好的英译中技术社区,最懂读者和译者的翻译平台:

34.4k
Apr 17, 2024
RepositoryPHP
raramuridesign/mysql-country-list

mysql insert country list into database

479
Nov 1, 2026