Skip to content

Commit

Permalink
Updated version. Lots of refactoring. Updated bundle patterns. Update…
Browse files Browse the repository at this point in the history
…d example. Updated readme and gif.
  • Loading branch information
NikKovIos committed Feb 28, 2018
1 parent 51b1395 commit 7745e75
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 452 deletions.
265 changes: 159 additions & 106 deletions Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

54 changes: 44 additions & 10 deletions Example/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,60 @@
import UIKit

class ExampleViewController: UIViewController {

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var outputLabel: UILabel!
@IBOutlet weak var topTextField: NKVPhonePickerTextField!
var bottomTextField: NKVPhonePickerTextField!

@IBOutlet weak var outputLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

topTextField.phonePickerDelegate = self
topTextField.favoriteCountriesLocaleIdentifiers = ["RU", "ER", "JM"]

/// Uncomment next line to try different settings
// topTextField.rightToLeftOrientation = true
// topTextField.shouldScrollToSelectedCountry = false
// topTextField.flagSize = CGSize(width: 30, height: 50)
// topTextField.setFlag(countryCode: nil)
// topTextField.isPlusPrefixExists = false

// topTextField.enablePlusPrefix = false

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

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

// You can also add NKVPhonePickerTextField programmatically ;)
addingProgrammatically()

// For keyboard
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}

@IBAction func didPressPhoneNumber(_ sender: UIButton) {
outputLabel.text = topTextField.phoneNumber
}

@IBAction func didPressCode(_ sender: UIButton) {
outputLabel.text = topTextField.code
}

@IBAction func didPressCountry(_ sender: UIButton) {
if let country = topTextField.country {
outputLabel.text = "\(country.countryCode); \(country.name)"
} else {
print("The country not setted.")
}
}

@IBAction func didPressOnView(_ sender: UITapGestureRecognizer) {
self.topTextField.resignFirstResponder()
self.view.endEditing(true)
}

/// You can add NKVPhonePickerTextField also programmatically
func addingProgrammatically() {
bottomTextField = NKVPhonePickerTextField(frame: CGRect(x: 0, y: 0, width: 0, height: 30))
bottomTextField.placeholder = "ex: 03123456"
Expand All @@ -59,7 +76,7 @@ class ExampleViewController: UIViewController {
bottomTextField.textColor = UIColor.white
bottomTextField.textFieldTextInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
bottomTextField.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(bottomTextField)
self.scrollView.addSubview(bottomTextField)

let views: [String : Any] = ["bottomTextField": self.bottomTextField]
let horizontalConstraints = NSLayoutConstraint.constraints(withVisualFormat:
Expand All @@ -77,4 +94,21 @@ class ExampleViewController: UIViewController {
view.addConstraints(horizontalConstraints)
view.addConstraints(verticalConstraints)
}


// MARK: - Keyboard handling

@objc func keyboardWillShow(notification: NSNotification) {
let userInfo: NSDictionary = notification.userInfo! as NSDictionary
let keyboardInfo = userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue
let keyboardSize = keyboardInfo.cgRectValue.size
let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}

@objc func keyboardWillHide(notification: NSNotification) {
scrollView.contentInset = .zero
scrollView.scrollIndicatorInsets = .zero
}
}
2 changes: 1 addition & 1 deletion Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>2.0.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
4 changes: 2 additions & 2 deletions NKVPhonePicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

Pod::Spec.new do |s|
s.name = 'NKVPhonePicker'
s.version = '1.2.1'
s.version = '2.0.0'
s.summary = 'A UITextField subclass to simplify the selection of country codes.'
s.description = <<-DESC
With this pod you can easily select country codes with just making your textFields class - the NKVPhonePickerTextField.
Support formatting phone to a specific pattern.
Support formatting phone to a specific pattern. Can select countries from the list.
DESC

s.homepage = 'https://github.com/NikKovIos/NKVPhonePicker'
Expand Down
2 changes: 1 addition & 1 deletion NKVPhonePicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
EB8491461ED4357C0069CD20 /* Example */ = {
isa = PBXGroup;
children = (
EB8491341ED435260069CD20 /* AppDelegate.swift */,
EB8491361ED435260069CD20 /* ExampleViewController.swift */,
EB8491341ED435260069CD20 /* AppDelegate.swift */,
EB84913B1ED435260069CD20 /* Assets.xcassets */,
EB8491381ED435260069CD20 /* Main.storyboard */,
EB84913D1ED435260069CD20 /* LaunchScreen.storyboard */,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

![Cocoapods](https://img.shields.io/badge/pod-available-brightgreen.svg?style=flat)
![Platform](https://img.shields.io/badge/platform-ios-blue.svg?style=flat)
![Version](https://img.shields.io/badge/version-1.2.1-blue.svg?style=flat)
![Version](https://img.shields.io/badge/version-2.0.0-blue.svg?style=flat)
![Swift version](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)
![License](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)

Expand All @@ -29,7 +29,7 @@ pod try NKVPhonePicker
```
*(don't forget to update your cocoapods master repo)*

If you're still using Swift 2.x - you can set
If you're still using Swift 2.x - you can set (The development for swift_2.x is deprecated. Stale version still exists)
```ruby
pod 'NKVPhonePicker', :git => "https://github.com/NikKovIos/NKVPhonePicker.git", :branch => "Swift_2.x"
```
Expand All @@ -44,11 +44,12 @@ Please, make an issue, if you need any features, or have bugs.

## Example
```swift
topTextField.phonePickerDelegate = self
topTextField.favoriteCountriesLocaleIdentifiers = ["RU", "ER", "JM"]
topTextField.rightToLeftOrientation = true
topTextField.shouldScrollToSelectedCountry = false
topTextField.flagSize = CGSize(width: 30, height: 50)
topTextField.setFlag(countryCode: nil)
topTextField.isPlusPrefixExists = false
topTextField.enablePlusPrefix = false

// Setting initial custom country
let country = Country.countryBy(countryCode: "EG")
Expand Down Expand Up @@ -100,7 +101,6 @@ view.addConstraints(verticalConstraints)
- [x] Add example
- [x] Max numbers count var (can do with custom pattern)
- [x] Patterns for each country
- [ ] Add my logo

## My other Repos

Expand Down
Binary file modified RepoAssets/Example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified RepoAssets/Screenshot_one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7745e75

Please sign in to comment.