GithubHelp home page GithubHelp logo

roleksandr / nkvphonepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikkovios/nkvphonepicker

0.0 1.0 0.0 3.86 MB

An UITextField subclass to simplify country code's picking.

License: MIT License

Swift 97.73% Ruby 2.27%

nkvphonepicker's Introduction


Cocoapods Platform Version Swift version License

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)

If you're still using Swift 2.x - you can set

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.favoriteCountriesLocaleIdentifiers = ["RU", "ER", "JM"]
topTextField.shouldScrollToSelectedCountry = false
topTextField.flagSize = CGSize(width: 30, height: 50)
topTextField.setFlag(countryCode: nil)
topTextField.isPlusPrefixExists = 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
self.view.addSubview(bottomTextField)
        
let views: [String : Any] = ["bottomTextField": self.bottomTextField]
let horizontalConstraints = NSLayoutConstraint.constraints(withVisualFormat:
            "H:|-15-[bottomTextField]-15-|",
                                                          options: [],
                                                          metrics: nil,
                                                          views: views)
        
let verticalConstraints = NSLayoutConstraint.constraints(withVisualFormat:
            "V:|-(>=0)-[bottomTextField(30)]-15-|",
                                                          options: [],
                                                          metrics: nil,
                                                          views: views)
        
view.addConstraints(horizontalConstraints)
view.addConstraints(verticalConstraints)
view.addConstraints(horizontalConstraints)
view.addConstraints(verticalConstraints)
}

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
  • Add my logo

My other Repos

by Nik Kov

http://nik-kov.com

nkvphonepicker's People

Contributors

legoless avatar nikkovios avatar

Watchers

 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.