From cc616ecf2ab80aaaf62feb8f05a8c442e2898d54 Mon Sep 17 00:00:00 2001 From: Justin Bergen Date: Wed, 19 Feb 2020 15:22:34 -0700 Subject: [PATCH 1/2] Added support for country name in view Also updated the demo app and tested --- CountryPickerView/CountryPickerView.swift | 15 ++-- .../Base.lproj/Main.storyboard | 85 +++++++++++++------ .../DemoViewController.swift | 5 +- CountryPickerViewDemo/Podfile.lock | 6 +- 4 files changed, 74 insertions(+), 37 deletions(-) diff --git a/CountryPickerView/CountryPickerView.swift b/CountryPickerView/CountryPickerView.swift index 204f915..4a94a12 100644 --- a/CountryPickerView/CountryPickerView.swift +++ b/CountryPickerView/CountryPickerView.swift @@ -46,16 +46,21 @@ public class CountryPickerView: NibView { } @IBOutlet public weak var countryDetailsLabel: UILabel! - // Show/Hide the country code on the view. + /// Show/Hide the country code on the view. public var showCountryCodeInView = true { didSet { setup() } } - // Show/Hide the phone code on the view. + /// Show/Hide the phone code on the view. public var showPhoneCodeInView = true { didSet { setup() } } + /// Show/Hide the country name on the view. + public var showCountryNameInView = false { + didSet { setup() } + } + /// Change the font of phone code public var font = UIFont.systemFont(ofSize: 17.0) { didSet { setup() } @@ -109,10 +114,10 @@ public class CountryPickerView: NibView { if showPhoneCodeInView && showCountryCodeInView { countryDetailsLabel.text = "(\(selectedCountry.code)) \(selectedCountry.phoneCode)" return - } - - if showCountryCodeInView || showPhoneCodeInView { + } else if showCountryCodeInView || showPhoneCodeInView { countryDetailsLabel.text = showCountryCodeInView ? selectedCountry.code : selectedCountry.phoneCode + } else if showCountryNameInView { + countryDetailsLabel.text = selectedCountry.localizedName() } else { countryDetailsLabel.text = nil } diff --git a/CountryPickerViewDemo/CountryPickerViewDemo/Base.lproj/Main.storyboard b/CountryPickerViewDemo/CountryPickerViewDemo/Base.lproj/Main.storyboard index 172bc68..b96dafb 100644 --- a/CountryPickerViewDemo/CountryPickerViewDemo/Base.lproj/Main.storyboard +++ b/CountryPickerViewDemo/CountryPickerViewDemo/Base.lproj/Main.storyboard @@ -1,11 +1,9 @@ - - - - + + - + @@ -15,7 +13,7 @@ - + @@ -38,21 +36,21 @@ - - + + - + - - + @@ -102,7 +100,7 @@ - + @@ -132,8 +130,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -164,7 +193,7 @@ - + @@ -195,7 +224,7 @@ - + @@ -226,7 +255,7 @@ - + @@ -258,7 +287,7 @@ - + @@ -292,7 +321,7 @@ - + @@ -305,8 +334,7 @@ - - + @@ -332,10 +360,10 @@ - + - + - + - + - +