diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index 9fcade2..04144dd 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -22,122 +22,174 @@ - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - + - - - - - - - - - - - - - - - - + + + + @@ -145,6 +197,7 @@ + diff --git a/Example/ExampleViewController.swift b/Example/ExampleViewController.swift index f085889..130b45e 100644 --- a/Example/ExampleViewController.swift +++ b/Example/ExampleViewController.swift @@ -8,24 +8,26 @@ 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" : "# ### ### ## ##", @@ -33,18 +35,33 @@ class ExampleViewController: UIViewController { // 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" @@ -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: @@ -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 + } } diff --git a/Example/Info.plist b/Example/Info.plist index efd6c1f..c169bce 100644 --- a/Example/Info.plist +++ b/Example/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.1 + 2.0.0 CFBundleVersion 1 LSRequiresIPhoneOS diff --git a/NKVPhonePicker.podspec b/NKVPhonePicker.podspec index 0104fcc..5e2e794 100755 --- a/NKVPhonePicker.podspec +++ b/NKVPhonePicker.podspec @@ -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' diff --git a/NKVPhonePicker.xcodeproj/project.pbxproj b/NKVPhonePicker.xcodeproj/project.pbxproj index b52ee59..2749d84 100644 --- a/NKVPhonePicker.xcodeproj/project.pbxproj +++ b/NKVPhonePicker.xcodeproj/project.pbxproj @@ -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 */, diff --git a/README.md b/README.md index c59d5b7..3ac6467 100755 --- a/README.md +++ b/README.md @@ -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) @@ -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" ``` @@ -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") @@ -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 diff --git a/RepoAssets/Example.gif b/RepoAssets/Example.gif index a604b00..395d85a 100644 Binary files a/RepoAssets/Example.gif and b/RepoAssets/Example.gif differ diff --git a/RepoAssets/Screenshot_one.png b/RepoAssets/Screenshot_one.png index f2b3aa9..e56ccf1 100644 Binary files a/RepoAssets/Screenshot_one.png and b/RepoAssets/Screenshot_one.png differ diff --git a/Sources/Bundle/Countries.bundle/Data/countryCodes.json b/Sources/Bundle/Countries.bundle/Data/countryCodes.json index 09e38a0..d061eb5 100755 --- a/Sources/Bundle/Countries.bundle/Data/countryCodes.json +++ b/Sources/Bundle/Countries.bundle/Data/countryCodes.json @@ -1,1065 +1,1071 @@ [ { +"name": "DummyPlaceholder", +"dial_code": "?", +"code": "DP", +"format": "################" +}, +{ "name": "Afghanistan", "dial_code": "93", "code": "AF", - "format": "################" + "format": "## ##############" }, { "name": "Aland Islands", "dial_code": "358", "code": "AX", - "format": "################" + "format": "### #############" }, { "name": "Albania", "dial_code": "355", "code": "AL", - "format": "################" + "format": "### #############" }, { "name": "Algeria", "dial_code": "213", "code": "DZ", - "format": "################" + "format": "### #############" }, { "name": "AmericanSamoa", "dial_code": "1684", "code": "AS", - "format": "################" + "format": "# ### ############" }, { "name": "Andorra", "dial_code": "376", "code": "AD", - "format": "################" + "format": "### #############" }, { "name": "Angola", "dial_code": "244", "code": "AO", - "format": "################" + "format": "### #############" }, { "name": "Anguilla", "dial_code": "1264", "code": "AI", - "format": "################" + "format": "# ### ############" }, { "name": "Antarctica", "dial_code": "672", "code": "AQ", - "format": "################" + "format": "### #############" }, { "name": "Antigua and Barbuda", "dial_code": "1268", "code": "AG", - "format": "################" + "format": "# ### ############" }, { "name": "Argentina", "dial_code": "54", "code": "AR", - "format": "################" + "format": "## ##############" }, { "name": "Armenia", "dial_code": "374", "code": "AM", - "format": "################" + "format": "### #############" }, { "name": "Aruba", "dial_code": "297", "code": "AW", - "format": "################" + "format": "### #############" }, { "name": "Australia", "dial_code": "61", "code": "AU", - "format": "################" + "format": "## #### ### ###" }, { "name": "Austria", "dial_code": "43", "code": "AT", - "format": "################" + "format": "## ##############" }, { "name": "Azerbaijan", "dial_code": "994", "code": "AZ", -"format": "################" +"format": "### #############" }, { "name": "Bahamas", "dial_code": "1242", "code": "BS", -"format": "################" +"format": "# ### ############" }, { "name": "Bahrain", "dial_code": "973", "code": "BH", - "format": "################" + "format": "### #############" }, { "name": "Bangladesh", "dial_code": "880", "code": "BD", - "format": "################" + "format": "### #############" }, { "name": "Barbados", "dial_code": "1246", "code": "BB", - "format": "################" + "format": "# ### ############" }, { "name": "Belarus", "dial_code": "375", "code": "BY", - "format": "################" + "format": "### #############" }, { "name": "Belgium", "dial_code": "32", "code": "BE", - "format": "################" + "format": "## ##############" }, { "name": "Belize", "dial_code": "501", "code": "BZ", - "format": "################" + "format": "### #############" }, { "name": "Benin", "dial_code": "229", "code": "BJ", - "format": "################" + "format": "### #############" }, { "name": "Bermuda", "dial_code": "1441", "code": "BM", - "format": "################" + "format": "# ### ############" }, { "name": "Bhutan", "dial_code": "975", "code": "BT", - "format": "################" + "format": "### #############" }, { "name": "Bolivia, Plurinational State of", "dial_code": "591", "code": "BO", - "format": "################" + "format": "### #############" }, { "name": "Bosnia and Herzegovina", "dial_code": "387", "code": "BA", - "format": "################" + "format": "### #############" }, { "name": "Botswana", "dial_code": "267", "code": "BW", - "format": "################" + "format": "### #############" }, { "name": "Brazil", "dial_code": "55", "code": "BR", - "format": "################" + "format": "## ##############" }, { "name": "British Indian Ocean Territory", "dial_code": "246", "code": "IO", - "format": "################" + "format": "### #############" }, { "name": "Brunei Darussalam", "dial_code": "673", "code": "BN", - "format": "################" + "format": "### #############" }, { "name": "Bulgaria", "dial_code": "359", "code": "BG", - "format": "################" + "format": "### #############" }, { "name": "Burkina Faso", "dial_code": "226", "code": "BF", - "format": "################" + "format": "### #############" }, { "name": "Burundi", "dial_code": "257", "code": "BI", - "format": "################" + "format": "### #############" }, { "name": "Cambodia", "dial_code": "855", "code": "KH", - "format": "################" + "format": "### #############" }, { "name": "Cameroon", "dial_code": "237", "code": "CM", - "format": "################" + "format": "### #############" }, { "name": "Canada", "dial_code": "1", "code": "CA", - "format": "################" + "format": "# ### ### ####" }, { "name": "Cape Verde", "dial_code": "238", "code": "CV", - "format": "################" + "format": "### #############" }, { "name": "Cayman Islands", -"dial_code": " 345", +"dial_code": "345", "code": "KY", - "format": "################" + "format": "### #############" }, { "name": "Central African Republic", "dial_code": "236", "code": "CF", - "format": "################" + "format": "### #############" }, { "name": "Chad", "dial_code": "235", "code": "TD", - "format": "################" + "format": "### #############" }, { "name": "Chile", "dial_code": "56", "code": "CL", - "format": "################" + "format": "## ##############" }, { "name": "China", "dial_code": "86", "code": "CN", - "format": "################" + "format": "## ##############" }, { "name": "Christmas Island", "dial_code": "61", "code": "CX", - "format": "################" + "format": "## ##############" }, { "name": "Cocos (Keeling) Islands", "dial_code": "61", "code": "CC", - "format": "################" + "format": "## ##############" }, { "name": "Colombia", "dial_code": "57", "code": "CO", - "format": "################" + "format": "## ##############" }, { "name": "Comoros", "dial_code": "269", "code": "KM", - "format": "################" + "format": "### #############" }, { "name": "Congo", "dial_code": "242", "code": "CG", - "format": "################" + "format": "### ## ## #####" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "243", "code": "CD", - "format": "################" + "format": "### #############" }, { "name": "Cook Islands", "dial_code": "682", "code": "CK", - "format": "################" + "format": "### #############" }, { "name": "Costa Rica", "dial_code": "506", "code": "CR", - "format": "################" + "format": "### #############" }, { "name": "Cote d'Ivoire", "dial_code": "225", "code": "CI", - "format": "################" + "format": "### #############" }, { "name": "Croatia", "dial_code": "385", "code": "HR", - "format": "################" + "format": "### #############" }, { "name": "Cuba", "dial_code": "53", "code": "CU", - "format": "################" + "format": "## ##############" }, { "name": "Cyprus", "dial_code": "357", "code": "CY", - "format": "################" + "format": "### #############" }, { "name": "Czech Republic", "dial_code": "420", "code": "CZ", - "format": "################" + "format": "### #############" }, { "name": "Denmark", "dial_code": "45", "code": "DK", - "format": "################" + "format": "## ##############" }, { "name": "Djibouti", "dial_code": "253", "code": "DJ", - "format": "################" + "format": "### #############" }, { "name": "Dominica", "dial_code": "1767", "code": "DM", - "format": "################" + "format": "# ### ############" }, { "name": "Dominican Republic", "dial_code": "1849", "code": "DO", - "format": "################" + "format": "# ### ############" }, { "name": "Ecuador", "dial_code": "593", "code": "EC", - "format": "################" + "format": "### #############" }, { "name": "Egypt", "dial_code": "20", "code": "EG", - "format": "################" + "format": "## ##############" }, { "name": "El Salvador", "dial_code": "503", "code": "SV", - "format": "################" + "format": "### #############" }, { "name": "Equatorial Guinea", "dial_code": "240", "code": "GQ", - "format": "################" + "format": "### #############" }, { "name": "Eritrea", "dial_code": "291", "code": "ER", - "format": "################" + "format": "### #############" }, { "name": "Estonia", "dial_code": "372", "code": "EE", - "format": "################" + "format": "### #############" }, { "name": "Ethiopia", "dial_code": "251", "code": "ET", - "format": "################" + "format": "### #############" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "500", "code": "FK", - "format": "################" + "format": "### #############" }, { "name": "Faroe Islands", "dial_code": "298", "code": "FO", - "format": "################" + "format": "### #############" }, { "name": "Fiji", "dial_code": "679", "code": "FJ", - "format": "################" + "format": "### #############" }, { "name": "Finland", "dial_code": "358", "code": "FI", - "format": "################" + "format": "### #############" }, { "name": "France", "dial_code": "33", "code": "FR", - "format": "################" + "format": "## ##############" }, { "name": "French Guiana", "dial_code": "594", "code": "GF", - "format": "################" + "format": "### #############" }, { "name": "French Polynesia", "dial_code": "689", "code": "PF", - "format": "################" + "format": "### #############" }, { "name": "Gabon", "dial_code": "241", "code": "GA", - "format": "################" + "format": "### #############" }, { "name": "Gambia", "dial_code": "220", "code": "GM", - "format": "################" + "format": "### #############" }, { "name": "Georgia", "dial_code": "995", "code": "GE", - "format": "################" + "format": "### #############" }, { "name": "Germany", "dial_code": "49", "code": "DE", - "format": "################" + "format": "## ##############" }, { "name": "Ghana", "dial_code": "233", "code": "GH", - "format": "################" + "format": "### #############" }, { "name": "Gibraltar", "dial_code": "350", "code": "GI", - "format": "################" + "format": "### #############" }, { "name": "Greece", "dial_code": "30", "code": "GR", - "format": "################" + "format": "## ##############" }, { "name": "Greenland", "dial_code": "299", "code": "GL", - "format": "################" + "format": "### #############" }, { "name": "Grenada", "dial_code": "1473", "code": "GD", - "format": "################" + "format": "# ### ############" }, { "name": "Guadeloupe", "dial_code": "590", "code": "GP", - "format": "################" + "format": "### #############" }, { "name": "Guam", "dial_code": "1671", "code": "GU", - "format": "################" + "format": "# ### ############" }, { "name": "Guatemala", "dial_code": "502", "code": "GT", - "format": "################" + "format": "### #############" }, { "name": "Guernsey", "dial_code": "44", "code": "GG", - "format": "################" + "format": "## ##############" }, { "name": "Guinea", "dial_code": "224", "code": "GN", - "format": "################" + "format": "### #############" }, { "name": "Guinea-Bissau", "dial_code": "245", "code": "GW", - "format": "################" + "format": "### #############" }, { "name": "Guyana", "dial_code": "595", "code": "GY", - "format": "################" + "format": "### #############" }, { "name": "Haiti", "dial_code": "509", "code": "HT", - "format": "################" + "format": "### #############" }, { "name": "Holy See (Vatican City State)", "dial_code": "379", "code": "VA", - "format": "################" + "format": "### #############" }, { "name": "Honduras", "dial_code": "504", "code": "HN", - "format": "################" + "format": "### #############" }, { "name": "Hong Kong", "dial_code": "852", "code": "HK", - "format": "################" + "format": "### #############" }, { "name": "Hungary", "dial_code": "36", "code": "HU", - "format": "################" + "format": "## ##############" }, { "name": "Iceland", "dial_code": "354", "code": "IS", - "format": "################" + "format": "### #############" }, { "name": "India", "dial_code": "91", "code": "IN", - "format": "################" + "format": "## ##############" }, { "name": "Indonesia", "dial_code": "62", "code": "ID", - "format": "################" + "format": "## ##############" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "98", "code": "IR", - "format": "################" + "format": "## ##############" }, { "name": "Iraq", "dial_code": "964", "code": "IQ", - "format": "################" + "format": "### #############" }, { "name": "Ireland", "dial_code": "353", "code": "IE", - "format": "################" + "format": "### #############" }, { "name": "Isle of Man", "dial_code": "44", "code": "IM", - "format": "################" + "format": "## ##############" }, { "name": "Israel", "dial_code": "972", "code": "IL", - "format": "################" + "format": "### #############" }, { "name": "Italy", "dial_code": "39", "code": "IT", - "format": "################" + "format": "## ##############" }, { "name": "Jamaica", "dial_code": "1876", "code": "JM", - "format": "################" + "format": "# ### ############" }, { "name": "Japan", "dial_code": "81", "code": "JP", - "format": "################" + "format": "## ##############" }, { "name": "Jersey", "dial_code": "44", "code": "JE", - "format": "################" + "format": "## ##############" }, { "name": "Jordan", "dial_code": "962", "code": "JO", - "format": "################" + "format": "### #############" }, { "name": "Kazakhstan", "dial_code": "77", "code": "KZ", - "format": "################" + "format": "## ##############" }, { "name": "Kenya", "dial_code": "254", "code": "KE", - "format": "################" + "format": "### #############" }, { "name": "Kiribati", "dial_code": "686", "code": "KI", - "format": "################" + "format": "### #############" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "850", "code": "KP", - "format": "################" + "format": "### #############" }, { "name": "Korea, Republic of South Korea", "dial_code": "82", "code": "KR", - "format": "################" + "format": "## ##############" }, { "name": "Kuwait", "dial_code": "965", "code": "KW", - "format": "################" + "format": "### #############" }, { "name": "Kyrgyzstan", "dial_code": "996", "code": "KG", - "format": "################" + "format": "### #############" }, { "name": "Laos", "dial_code": "856", "code": "LA", - "format": "################" + "format": "### #############" }, { "name": "Latvia", "dial_code": "371", "code": "LV", - "format": "################" + "format": "### #############" }, { "name": "Lebanon", "dial_code": "961", "code": "LB", - "format": "################" + "format": "### #############" }, { "name": "Lesotho", "dial_code": "266", "code": "LS", - "format": "################" + "format": "### #############" }, { "name": "Liberia", "dial_code": "231", "code": "LR", - "format": "################" + "format": "### #############" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "218", "code": "LY", - "format": "################" + "format": "### #############" }, { "name": "Liechtenstein", "dial_code": "423", "code": "LI", - "format": "################" + "format": "### #############" }, { "name": "Lithuania", "dial_code": "370", "code": "LT", - "format": "################" + "format": "### #############" }, { "name": "Luxembourg", "dial_code": "352", "code": "LU", - "format": "################" + "format": "### #############" }, { "name": "Macao", "dial_code": "853", "code": "MO", - "format": "################" + "format": "### #############" }, { "name": "Macedonia", "dial_code": "389", "code": "MK", - "format": "################" + "format": "### #############" }, { "name": "Madagascar", "dial_code": "261", "code": "MG", - "format": "################" + "format": "### #############" }, { "name": "Malawi", "dial_code": "265", "code": "MW", - "format": "################" + "format": "### #############" }, { "name": "Malaysia", "dial_code": "60", "code": "MY", - "format": "################" + "format": "## ##############" }, { "name": "Maldives", "dial_code": "960", "code": "MV", - "format": "################" + "format": "### #############" }, { "name": "Mali", "dial_code": "223", "code": "ML", - "format": "################" + "format": "### #############" }, { "name": "Malta", "dial_code": "356", "code": "MT", - "format": "################" + "format": "### #############" }, { "name": "Marshall Islands", "dial_code": "692", "code": "MH", - "format": "################" + "format": "### #############" }, { "name": "Martinique", "dial_code": "596", "code": "MQ", - "format": "################" + "format": "### #############" }, { "name": "Mauritania", "dial_code": "222", "code": "MR", - "format": "################" + "format": "### #############" }, { "name": "Mauritius", "dial_code": "230", "code": "MU", - "format": "################" + "format": "### #############" }, { "name": "Mayotte", "dial_code": "262", "code": "YT", - "format": "################" + "format": "### #############" }, { "name": "Mexico", "dial_code": "52", "code": "MX", - "format": "################" + "format": "## ##############" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "691", "code": "FM", - "format": "################" + "format": "### #############" }, { "name": "Moldova", "dial_code": "373", "code": "MD", - "format": "################" + "format": "### #############" }, { "name": "Monaco", "dial_code": "377", "code": "MC", - "format": "################" + "format": "### #############" }, { "name": "Mongolia", "dial_code": "976", "code": "MN", - "format": "################" + "format": "### #############" }, { "name": "Montenegro", "dial_code": "382", "code": "ME", - "format": "################" + "format": "### #############" }, { "name": "Montserrat", "dial_code": "1664", "code": "MS", - "format": "################" + "format": "# ### ############" }, { "name": "Morocco", "dial_code": "212", "code": "MA", - "format": "################" + "format": "### #############" }, { "name": "Mozambique", "dial_code": "258", "code": "MZ", - "format": "################" + "format": "### #############" }, { "name": "Myanmar", "dial_code": "95", "code": "MM", - "format": "################" + "format": "## ##############" }, { "name": "Namibia", "dial_code": "264", "code": "NA", - "format": "################" + "format": "### #############" }, { "name": "Nauru", "dial_code": "674", "code": "NR", - "format": "################" + "format": "### #############" }, { "name": "Nepal", "dial_code": "977", "code": "NP", - "format": "################" + "format": "### #############" }, { "name": "Netherlands", "dial_code": "31", "code": "NL", - "format": "################" + "format": "## ##############" }, { "name": "Netherlands Antilles", "dial_code": "599", "code": "AN", - "format": "################" + "format": "### #############" }, { "name": "New Caledonia", "dial_code": "687", "code": "NC", - "format": "################" + "format": "### #############" }, { "name": "New Zealand", "dial_code": "64", "code": "NZ", - "format": "################" + "format": "## ##############" }, { "name": "Nicaragua", "dial_code": "505", "code": "NI", - "format": "################" + "format": "### #############" }, { "name": "Niger", "dial_code": "227", "code": "NE", - "format": "################" + "format": "### #############" }, { "name": "Nigeria", "dial_code": "234", "code": "NG", - "format": "################" + "format": "### #############" }, { "name": "Niue", "dial_code": "683", "code": "NU", - "format": "################" + "format": "### #############" }, { "name": "Norfolk Island", "dial_code": "672", "code": "NF", - "format": "################" + "format": "### #############" }, { "name": "Northern Mariana Islands", "dial_code": "1670", "code": "MP", - "format": "################" + "format": "# ### ############" }, { "name": "Norway", "dial_code": "47", "code": "NO", - "format": "################" + "format": "## ##############" }, { "name": "Oman", "dial_code": "968", "code": "OM", - "format": "################" + "format": "### #############" }, { "name": "Pakistan", "dial_code": "92", "code": "PK", - "format": "################" + "format": "## ##############" }, { "name": "Palau", "dial_code": "680", "code": "PW", - "format": "################" + "format": "### #############" }, { "name": "Palestinian Territory, Occupied", "dial_code": "970", "code": "PS", - "format": "################" + "format": "### #############" }, { "name": "Panama", "dial_code": "507", "code": "PA", - "format": "################" + "format": "### #############" }, { "name": "Papua New Guinea", "dial_code": "675", "code": "PG", - "format": "################" + "format": "### #############" }, { "name": "Paraguay", "dial_code": "595", "code": "PY", - "format": "################" + "format": "### #############" }, { "name": "Peru", "dial_code": "51", "code": "PE", - "format": "################" + "format": "## ##############" }, { "name": "Philippines", "dial_code": "63", "code": "PH", - "format": "################" + "format": "## ##############" }, { "name": "Pitcairn", "dial_code": "872", "code": "PN", - "format": "################" + "format": "### #############" }, { "name": "Poland", "dial_code": "48", "code": "PL", - "format": "################" + "format": "## ##############" }, { "name": "Portugal", "dial_code": "351", "code": "PT", - "format": "################" + "format": "### #############" }, { "name": "Puerto Rico", "dial_code": "1939", "code": "PR", - "format": "################" + "format": "# ### ############" }, { "name": "Qatar", "dial_code": "974", "code": "QA", - "format": "################" + "format": "### #############" }, { "name": "Romania", "dial_code": "40", "code": "RO", - "format": "################" + "format": "## ##############" }, { "name": "Russia", @@ -1071,384 +1077,384 @@ "name": "Rwanda", "dial_code": "250", "code": "RW", - "format": "################" + "format": "### #############" }, { "name": "Reunion", "dial_code": "262", "code": "RE", - "format": "################" + "format": "### #############" }, { "name": "Saint Barthelemy", "dial_code": "590", "code": "BL", - "format": "################" + "format": "### #############" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "290", "code": "SH", - "format": "################" + "format": "### #############" }, { "name": "Saint Kitts and Nevis", "dial_code": "1869", "code": "KN", - "format": "################" + "format": "# ### ############" }, { "name": "Saint Lucia", "dial_code": "1758", "code": "LC", - "format": "################" + "format": "# ### ############" }, { "name": "Saint Martin", "dial_code": "590", "code": "MF", - "format": "################" + "format": "### #############" }, { "name": "Saint Pierre and Miquelon", "dial_code": "508", "code": "PM", - "format": "################" + "format": "### #############" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "1784", "code": "VC", - "format": "################" + "format": "# ### ############" }, { "name": "Samoa", "dial_code": "685", "code": "WS", - "format": "################" + "format": "### #############" }, { "name": "San Marino", "dial_code": "378", "code": "SM", - "format": "################" + "format": "### #############" }, { "name": "Sao Tome and Principe", "dial_code": "239", "code": "ST", - "format": "################" + "format": "### #############" }, { "name": "Saudi Arabia", "dial_code": "966", "code": "SA", - "format": "################" + "format": "### #############" }, { "name": "Senegal", "dial_code": "221", "code": "SN", - "format": "################" + "format": "### #############" }, { "name": "Serbia", "dial_code": "381", "code": "RS", - "format": "################" + "format": "### #############" }, { "name": "Seychelles", "dial_code": "248", "code": "SC", - "format": "################" + "format": "### #############" }, { "name": "Sierra Leone", "dial_code": "232", "code": "SL", - "format": "################" + "format": "### #############" }, { "name": "Singapore", "dial_code": "65", "code": "SG", - "format": "################" + "format": "## ##############" }, { "name": "Slovakia", "dial_code": "421", "code": "SK", - "format": "################" + "format": "### #############" }, { "name": "Slovenia", "dial_code": "386", "code": "SI", - "format": "################" + "format": "### #############" }, { "name": "Solomon Islands", "dial_code": "677", "code": "SB", - "format": "################" + "format": "### #############" }, { "name": "Somalia", "dial_code": "252", "code": "SO", - "format": "################" + "format": "### #############" }, { "name": "South Africa", "dial_code": "27", "code": "ZA", - "format": "################" + "format": "## ##############" }, { "name": "South Sudan", "dial_code": "211", "code": "SS", - "format": "################" + "format": "### #############" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "500", "code": "GS", - "format": "################" + "format": "### #############" }, { "name": "Spain", "dial_code": "34", "code": "ES", - "format": "################" + "format": "## ##############" }, { "name": "Sri Lanka", "dial_code": "94", "code": "LK", - "format": "################" + "format": "## ##############" }, { "name": "Sudan", "dial_code": "249", "code": "SD", - "format": "################" + "format": "### #############" }, { "name": "Suriname", "dial_code": "597", "code": "SR", - "format": "################" + "format": "### #############" }, { "name": "Svalbard and Jan Mayen", "dial_code": "47", "code": "SJ", - "format": "################" + "format": "## ##############" }, { "name": "Swaziland", "dial_code": "268", "code": "SZ", - "format": "################" + "format": "### #############" }, { "name": "Sweden", "dial_code": "46", "code": "SE", - "format": "################" + "format": "## ##############" }, { "name": "Switzerland", "dial_code": "41", "code": "CH", - "format": "################" + "format": "## ##############" }, { "name": "Syrian Arab Republic", "dial_code": "963", "code": "SY", - "format": "################" + "format": "### #############" }, { "name": "Taiwan", "dial_code": "886", "code": "TW", - "format": "################" + "format": "### #############" }, { "name": "Tajikistan", "dial_code": "992", "code": "TJ", - "format": "################" + "format": "### #############" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "255", "code": "TZ", - "format": "################" + "format": "### #############" }, { "name": "Thailand", "dial_code": "66", "code": "TH", - "format": "################" + "format": "## ##############" }, { "name": "Timor-Leste", "dial_code": "670", "code": "TL", - "format": "################" + "format": "### #############" }, { "name": "Togo", "dial_code": "228", "code": "TG", - "format": "################" + "format": "### #############" }, { "name": "Tokelau", "dial_code": "690", "code": "TK", - "format": "################" + "format": "### #############" }, { "name": "Tonga", "dial_code": "676", "code": "TO", - "format": "################" + "format": "### #############" }, { "name": "Trinidad and Tobago", "dial_code": "1868", "code": "TT", - "format": "################" + "format": "# ### ############" }, { "name": "Tunisia", "dial_code": "216", "code": "TN", - "format": "################" + "format": "### #############" }, { "name": "Turkey", "dial_code": "90", "code": "TR", - "format": "################" + "format": "## ##############" }, { "name": "Turkmenistan", "dial_code": "993", "code": "TM", - "format": "################" + "format": "### #############" }, { "name": "Turks and Caicos Islands", "dial_code": "1649", "code": "TC", - "format": "################" + "format": "# ### ############" }, { "name": "Tuvalu", "dial_code": "688", "code": "TV", - "format": "################" + "format": "### #############" }, { "name": "Uganda", "dial_code": "256", "code": "UG", - "format": "################" + "format": "### #############" }, { "name": "Ukraine", "dial_code": "380", "code": "UA", - "format": "################" + "format": "### #############" }, { "name": "United Arab Emirates", "dial_code": "971", "code": "AE", - "format": "################" + "format": "### #############" }, { "name": "United Kingdom", "dial_code": "44", "code": "GB", - "format": "################" + "format": "## #### ######" }, { "name": "United States", "dial_code": "1", "code": "US", - "format": "################" + "format": "# ### ### ####" }, { "name": "Uruguay", "dial_code": "598", "code": "UY", - "format": "################" + "format": "### #############" }, { "name": "Uzbekistan", "dial_code": "998", "code": "UZ", - "format": "################" + "format": "### #############" }, { "name": "Vanuatu", "dial_code": "678", "code": "VU", - "format": "################" + "format": "### #############" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "58", "code": "VE", - "format": "################" + "format": "## ##############" }, { "name": "Vietnam", "dial_code": "84", "code": "VN", - "format": "################" + "format": "## ##############" }, { "name": "Virgin Islands, British", "dial_code": "1284", "code": "VG", - "format": "################" + "format": "# ### ############" }, { "name": "Virgin Islands, U.S.", "dial_code": "1340", "code": "VI", - "format": "################" + "format": "# ### ############" }, { "name": "Wallis and Futuna", "dial_code": "681", "code": "WF", - "format": "################" + "format": "### #############" }, { "name": "Yemen", "dial_code": "967", "code": "YE", - "format": "################" + "format": "### #############" }, { "name": "Zambia", "dial_code": "260", "code": "ZM", - "format": "################" + "format": "### #############" }, { "name": "Zimbabwe", "dial_code": "263", "code": "ZW", - "format": "################" + "format": "### #############" } ] diff --git a/Sources/Helpers/NKVSourcesHelper.swift b/Sources/Helpers/NKVSourcesHelper.swift index e3466cc..64a8583 100644 --- a/Sources/Helpers/NKVSourcesHelper.swift +++ b/Sources/Helpers/NKVSourcesHelper.swift @@ -21,7 +21,7 @@ public enum NKVSource { } init(phoneExtension: String) { - self = .phone(PhoneExtension(phoneExtension)) + self = .phoneExtension(PhoneExtension(phoneExtension)) } } @@ -39,9 +39,8 @@ struct NKVSourcesHelper { countryCode = country.countryCode case .code(let code): countryCode = code.code - case .phone: + case .phoneExtension: guard let country = Country.country(for: source) else { - print("⚠️ NKVSourcesHelper >>> Can't find a country for this phone code.") return nil } countryCode = country.countryCode diff --git a/Sources/Main/CountriesViewController.swift b/Sources/Main/CountriesViewController.swift index 58119a9..44d9436 100755 --- a/Sources/Main/CountriesViewController.swift +++ b/Sources/Main/CountriesViewController.swift @@ -46,9 +46,15 @@ public final class CountriesViewController: UITableViewController { /// The font of textLabel and detailedTextLabel public var cellsFont : UIFont? + + + + + // MARK: - Private + override public func viewDidLoad() { super.viewDidLoad() - + configurateCancelButton() setupCountries() setupSearchController() @@ -59,7 +65,6 @@ public final class CountriesViewController: UITableViewController { self.searchController.view.removeFromSuperview() } - // MARK: - Private fileprivate var searchController = UISearchController(searchResultsController: nil) /// An array with which all countries are presenting. This array works with search controller and tableView. fileprivate var filteredCountries: [[Country]]! @@ -232,7 +237,6 @@ extension CountriesViewController: UISearchResultsUpdating { if text.isEmpty { filteredCountries = unfilteredCountries } else { - // TODO: Check this code let decimalCharacters = CharacterSet.decimalDigits let decimalRange = text.rangeOfCharacter(from: decimalCharacters) if decimalRange != nil { @@ -242,8 +246,6 @@ extension CountriesViewController: UISearchResultsUpdating { let allCountriesArray: [Country] = NKVSourcesHelper.countries.filter { $0.name.range(of: text) != nil } filteredCountries = partioned(array: allCountriesArray, usingSelector: #selector(getter: Country.name)) } - // let allCountriesArray: [Country] = NKVSourcesHelper.countries.filter { $0.name.range(of: text) != nil } -// filteredCountries = partioned(array: allCountriesArray, usingSelector: #selector(getter: Country.name)) filteredCountries.insert([], at: 0) //Empty section for our favorites } tableView.reloadData() diff --git a/Sources/Main/NKVFlagView.swift b/Sources/Main/NKVFlagView.swift index a8f436e..981c54f 100644 --- a/Sources/Main/NKVFlagView.swift +++ b/Sources/Main/NKVFlagView.swift @@ -11,47 +11,43 @@ open class NKVFlagView: UIView { // MARK: - Interface - /// Shows what country is presenting now. + /// Shows what country is presenting now. The NKVPhoneTextField gets its value for `country` property from here. public var currentPresentingCountry: Country? + /// A designated method for setting a flag image + public func setFlag(with source: NKVSource) { + if let flagImage = NKVSourcesHelper.flag(for: source), + let newSettedCountry = Country.country(for: source) { + self.flagButton.setImage(flagImage, for: .normal) + currentPresentingCountry = newSettedCountry + textField.presenter.enablePhoneFormat(for: newSettedCountry) + } + } /// Size of the flag icon public var iconSize: CGSize { didSet { configureInstance() } } /// Shifting for the icon from top, left, bottom and right. public var insets: UIEdgeInsets { didSet { configureInstance() } } - /// A designated method for setting a flag image - public func setFlag(with source: NKVSource) { - currentPresentingCountry = Country.country(for: source) - - let flagImage = NKVSourcesHelper.flag(for: source) - self.flagButton.setImage(flagImage, for: .normal) - } - - public required init(with textField: UITextField) { + // MARK: - Initialization + + public required init(with textField: NKVPhonePickerTextField) { self.textField = textField self.insets = UIEdgeInsetsMake(7, 7, 7, 7) self.iconSize = CGSize(width: 18.0, height: textField.frame.height) super.init(frame: CGRect.zero) configureInstance() - - if let countryForCurrentPhoneLocalization = Country.currentCountry { - setFlag(with: NKVSource(country: countryForCurrentPhoneLocalization)) - } } override open func layoutSubviews() { updateFrame() } - - - // MARK: - Implementation - private var flagButton: UIButton = UIButton() - private weak var textField: UITextField! + public var flagButton: UIButton = UIButton() + private weak var textField: NKVPhonePickerTextField! private func configureInstance() { // Adding flag button to flag's view @@ -65,7 +61,6 @@ open class NKVFlagView: UIView { /// Set and update flag view's frame. private func updateFrame() { - // Setting flag view's frame self.frame = CGRect(x: 0, y: 0, width: insets.left + insets.right + iconSize.width, diff --git a/Sources/Main/NKVPhonePickerPresenter.swift b/Sources/Main/NKVPhonePickerPresenter.swift index 1b0408d..f21412a 100644 --- a/Sources/Main/NKVPhonePickerPresenter.swift +++ b/Sources/Main/NKVPhonePickerPresenter.swift @@ -6,8 +6,12 @@ // Copyright © 2018 nik.kov. All rights reserved. // +import UIKit + +/// Logic container for TextField class NKVPhonePickerPresenter { + /// Country setter public func setCountry(source: NKVSource) { setFlag(source: source) setCode(source: source) @@ -48,10 +52,32 @@ class NKVPhonePickerPresenter { } self.textField.setFormatting(country.formatPattern, replacementChar: "#") } - + /// If off - removing the plus prefix + public func plusPrefix(on: Bool) { + if !on { + textField.plusLabel?.removeFromSuperview() + textField.textFieldTextInsets = UIEdgeInsets.zero + } + } + + /// If on, moving flag and plus label to the right + public func isRightToLeftMode(on: Bool) { + var fontSize = (textField.font?.pointSize ?? 10) / 2 + fontSize = fontSize == 0 ? 5 : fontSize - + if on { + textField.rightViewMode = .always + textField.rightView = textField.flagView + textField.textAlignment = .right + textField.textFieldTextInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: fontSize) + } else { + textField.leftViewMode = .always + textField.leftView = textField.flagView + textField.textFieldTextInsets = UIEdgeInsets(top: 0, left: fontSize, bottom: 0, right: 0) + } + } + // MARK: - Initialization diff --git a/Sources/Main/NKVPhonePickerTextField.swift b/Sources/Main/NKVPhonePickerTextField.swift index 6d6f159..43ef723 100644 --- a/Sources/Main/NKVPhonePickerTextField.swift +++ b/Sources/Main/NKVPhonePickerTextField.swift @@ -30,45 +30,47 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { /// textField.customPhoneFormats = ["RU" : "# ### ### ## ##", "GB": "# #### #########"] public var customPhoneFormats: [String: String]? - /// Set to 'false' if you don't need the '+' prefix - public var isPlusPrefixExists: Bool = true { - didSet { - if isPlusPrefixExists == false { - plusLabel?.removeFromSuperview() - textFieldTextInsets = UIEdgeInsets.zero - } - } - } + /// Set to 'false' if you don't need the '+' prefix to be visible + public var enablePlusPrefix: Bool = true { didSet { presenter.plusPrefix(on: enablePlusPrefix) } } - /// Show is there a valid country flag (not with question mark). - public var isFlagExist: Bool = false - - /// Set to 'false' if you don't need to scroll to selected country in CountryPickerViewController. + /// Set to 'false' if you don't need to scroll to selected country in when CountryPickerViewController did appear. public var shouldScrollToSelectedCountry: Bool = true + /// Set to true for languages where flag and + must be at the right. For example for Arabic. + public var rightToLeftOrientation: Bool = false { didSet { presenter.isRightToLeftMode(on: rightToLeftOrientation) } } + // MARK: - Get /// Current selected country in TextField /// Use this var to set or get current selected country. /// nil if non country is selected - public var country: Country? { didSet { presenter.setCountry(source: NKVSource(country: country!)) }} - - /// The UIView subclass which contains flag icon. - open var flagView: NKVFlagView! - - /// The UILabel with plus if isPlusPrefixExists == true - open var plusLabel: UILabel? + public var country: Country? { + get { + return flagView.currentPresentingCountry + } + set { + if let newValue = newValue { + presenter.setCountry(source: NKVSource(country: newValue)) + } + } + } /// - Returns: Current phone number in textField without '+'. Ex: 79997773344. - public var phoneNumber: String { - return self.text?.cutSpaces.cutPluses ?? "" + public var phoneNumber: String? { + return self.text?.cutSpaces.cutPluses } /// - Returns: Current phone code without +. Ex: 7 - public var code: String { - return flagView.currentPresentingCountry.phoneExtension.cutPluses + public var code: String? { + return country?.phoneExtension } + /// The UIView subclass which contains flag icon. + open var flagView: NKVFlagView! + + /// The UILabel with plus if enablePlusPrefix == true + open var plusLabel: UILabel? + // MARK: - Set public func setCode(source: NKVSource) { @@ -81,7 +83,8 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { // MARK: - Customizing - // Country picker customization properties: + // MARK: Country Picker + public var pickerTitle: String? public var pickerTitleFont: UIFont? public var pickerCancelButtonTitle: String? @@ -89,6 +92,8 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { public var pickerCancelButtonFont: UIFont? public var pickerBarTintColor: UIColor? + // MARK: Text Field + /// Insets for text in textField public var textFieldTextInsets: UIEdgeInsets? { didSet { layoutSubviews() } } @@ -97,6 +102,8 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { /// Left and right insets affect on flag view. /// Top and bottom insets - on image only. public var flagInsets: UIEdgeInsets? { didSet { customizeSelf() } } + + /// Size of the flag icon public var flagSize: CGSize? { didSet { customizeSelf() } } @@ -132,24 +139,21 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { } private func initialize() { - self.leftViewMode = .always - self.keyboardType = .phonePad flagView = NKVFlagView(with: self) - self.leftView = flagView + self.keyboardType = .phonePad self.delegate = self - - var fontSize = (self.font?.pointSize ?? 10) / 2 - fontSize = fontSize == 0 ? 5 : fontSize - textFieldTextInsets = UIEdgeInsets(top: 0, left: fontSize, bottom: 0, right: 0) - - currentSelectedCountry = Country.currentCountry - flagView.flagButton.addTarget(self, action: #selector(presentCountriesViewController), for: .touchUpInside) self.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged) + + presenter.isRightToLeftMode(on: false) + + if let countryForCurrentPhoneLocalization = Country.currentCountry { + country = countryForCurrentPhoneLocalization + } } private func addPlusLabel() { - if isPlusPrefixExists && (plusLabel == nil) { + if enablePlusPrefix && (plusLabel == nil) { plusLabel = UILabel(frame: CGRect.zero) plusLabel?.backgroundColor = UIColor.clear plusLabel?.text = "+" @@ -157,9 +161,16 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { } plusLabel?.font = self.font plusLabel?.textColor = self.textColor - plusLabel?.frame = CGRect(x: self.flagView.frame.size.width, + + // Setting a plus label frame + let width = (self.font?.pointSize ?? 10) / 1.5 + var x = self.flagView.bounds.width + if rightToLeftOrientation { + x = self.bounds.width - width - self.flagView.bounds.width + } + plusLabel?.frame = CGRect(x: x, y: self.flagView.frame.origin.y, - width: (self.font?.pointSize ?? 10) / 1.5, + width: width, height: self.frame.size.height * 0.9) } @@ -180,7 +191,7 @@ open class NKVPhonePickerTextField: TextFieldPatternFormat { private func customizeCountryPicker(_ pickerVC: CountriesViewController) { pickerVC.shouldScrollToSelectedCountry = shouldScrollToSelectedCountry - if let currentSelectedCountry = currentSelectedCountry { + if let currentSelectedCountry = country { pickerVC.selectedCountry = currentSelectedCountry } if let favoriteCountriesLocaleIdentifiers = favoriteCountriesLocaleIdentifiers { @@ -244,7 +255,7 @@ extension NKVPhonePickerTextField: UITextFieldDelegate { @objc fileprivate func textFieldDidChange() { if let newString = self.text { if newString.count == 1 || newString.count == 0 { - self.setFlag(source: NKVSource(countryCode: "?")) + self.setFlag(source: NKVSource(country: Country.empty)) } let firstFourLetters = String(newString.prefix(5)) @@ -252,13 +263,3 @@ extension NKVPhonePickerTextField: UITextFieldDelegate { } } } - - - - -// New -extension NKVPhonePickerTextField { - - /// Возможность инициализировать с кастомным бандлом - /// Var для того, чтобы plus label был справа -} diff --git a/Sources/Main/TextFieldWithPattern.swift b/Sources/Main/TextFieldWithPattern.swift index 28c0d1c..eb87ea6 100644 --- a/Sources/Main/TextFieldWithPattern.swift +++ b/Sources/Main/TextFieldWithPattern.swift @@ -170,7 +170,6 @@ open class TextFieldPatternFormat: UITextField { @objc public func textDidChange() { var superText: String { return super.text ?? "" } - // TODO: - Isn't there more elegant way how to do this? let currentTextForFormatting: String if superText.count > _textWithoutSecureBullets.count { diff --git a/Sources/Models/Country.swift b/Sources/Models/Country.swift index 2cf4830..3793cf3 100755 --- a/Sources/Models/Country.swift +++ b/Sources/Models/Country.swift @@ -48,9 +48,8 @@ public class Country: NSObject { return Country.country(for: NKVSource(countryCode: currentCountryCode)) } - // TODO: понять что за + /// An empty country entity for test or other purposes. - /// "+" code returns a flag with question mark. + /// "?" country code returns a flag with question mark. public static var empty: Country { return Country(countryCode: "?", phoneExtension: "") } @@ -72,7 +71,6 @@ public class Country: NSObject { } } case .phoneExtension(let phoneExtension): - // TODO: Может есть лучший способ сравнивать телефоны чтобы достать страну? let phoneExtension = phoneExtension.phoneExtension.cutPluses for country in NKVSourcesHelper.countries { if phoneExtension == country.phoneExtension { diff --git a/Sources/Models/CountryCode.swift b/Sources/Models/CountryCode.swift index 3505e72..5a72dea 100644 --- a/Sources/Models/CountryCode.swift +++ b/Sources/Models/CountryCode.swift @@ -9,7 +9,7 @@ public struct CountryCode { var code: String - init?(source: NKVSource) { + init?(_ source: NKVSource) { switch source { case .country(let country): self.code = country.countryCode