From 5487f0095fa3ba1f26a0ada8673d978938ad440e Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 16:40:38 +0200 Subject: [PATCH 01/11] Fix phone number distance from flag --- Sources/FPNTextField.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index f6d4e414..c7a58517 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -150,7 +150,12 @@ open class FPNTextField: UITextField { NSLayoutConstraint(item: flagButton, attribute: .centerY, relatedBy: .equal, toItem: leftView, attribute: .centerY, multiplier: 1, constant: 0).isActive = true - NSLayoutConstraint(item: flagButton, attribute: .leading, relatedBy: .equal, toItem: leftView, attribute: .leading, multiplier: 1, constant: 0).isActive = true + var distanceFromFlag: CGFloat = 0.0 + if #available(iOS 13, *) { + distanceFromFlag = -4.0 + } + + NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: distanceFromFlag).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .trailing, relatedBy: .equal, toItem: leftView, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .top, relatedBy: .equal, toItem: leftView, attribute: .top, multiplier: 1, constant: 0).isActive = true From daa2fdc3f0eed44470e4831ca0b54cd4ffcd8b1d Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 17:14:11 +0200 Subject: [PATCH 02/11] Update podspec --- FlagPhoneNumber.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FlagPhoneNumber.podspec b/FlagPhoneNumber.podspec index 4264ce68..67cd4755 100644 --- a/FlagPhoneNumber.podspec +++ b/FlagPhoneNumber.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'FlagPhoneNumber' - s.version = '0.8.0' + s.version = '0.8.1' s.summary = 'A formatted phone number UITextField with country flag picker.' # This description is used to generate tags and improve search results. @@ -21,7 +21,7 @@ Pod::Spec.new do |s| FlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. DESC - s.homepage = 'https://github.com/chronotruck/FlagPhoneNumber' + s.homepage = 'https://github.com/Ku6ep/FlagPhoneNumber' s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } s.source = { :git => 'https://github.com/chronotruck/FlagPhoneNumber.git', :tag => s.version.to_s } From 13a4955794fd06980ec82d749e615b2789afc2b2 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 17:18:33 +0200 Subject: [PATCH 03/11] Update FlagPhoneNumber.podspec Fix podspec --- FlagPhoneNumber.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlagPhoneNumber.podspec b/FlagPhoneNumber.podspec index 67cd4755..3047a5e2 100644 --- a/FlagPhoneNumber.podspec +++ b/FlagPhoneNumber.podspec @@ -24,7 +24,7 @@ Pod::Spec.new do |s| s.homepage = 'https://github.com/Ku6ep/FlagPhoneNumber' s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } - s.source = { :git => 'https://github.com/chronotruck/FlagPhoneNumber.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/Ku6ep/FlagPhoneNumber.git', :tag => s.version.to_s } s.ios.deployment_target = '8.0' s.source_files = 'Sources/**/*.swift' From c5e4581c99e0ec45b748651fbde529c1235be198 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 17:26:38 +0200 Subject: [PATCH 04/11] Update FlagPhoneNumber.podspec --- FlagPhoneNumber.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FlagPhoneNumber.podspec b/FlagPhoneNumber.podspec index 3047a5e2..6ff12b74 100644 --- a/FlagPhoneNumber.podspec +++ b/FlagPhoneNumber.podspec @@ -7,7 +7,7 @@ # Pod::Spec.new do |s| - s.name = 'FlagPhoneNumber' + s.name = 'AUFlagPhoneNumber' s.version = '0.8.1' s.summary = 'A formatted phone number UITextField with country flag picker.' @@ -18,17 +18,17 @@ Pod::Spec.new do |s| # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC - FlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. + AUFlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. DESC - s.homepage = 'https://github.com/Ku6ep/FlagPhoneNumber' + s.homepage = 'https://github.com/Ku6ep/AUFlagPhoneNumber' s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } s.source = { :git => 'https://github.com/Ku6ep/FlagPhoneNumber.git', :tag => s.version.to_s } s.ios.deployment_target = '8.0' s.source_files = 'Sources/**/*.swift' - s.resource_bundles = {'FlagPhoneNumber' => ['Sources/Resources/**/*']} + s.resource_bundles = {'AUFlagPhoneNumber' => ['Sources/Resources/**/*']} s.swift_version = '5.0' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } From 1bb0a59bb84247749798563c561db3cc661fa37f Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 17:35:02 +0200 Subject: [PATCH 05/11] Change Podspec file --- FlagPhoneNumber.podspec | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 FlagPhoneNumber.podspec diff --git a/FlagPhoneNumber.podspec b/FlagPhoneNumber.podspec deleted file mode 100644 index 6ff12b74..00000000 --- a/FlagPhoneNumber.podspec +++ /dev/null @@ -1,38 +0,0 @@ -# -# Be sure to run `pod lib lint FlagPhoneNumber.podspec' to ensure this is a -# valid spec before submitting. -# -# Any lines starting with a # are optional, but their use is encouraged -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html -# - -Pod::Spec.new do |s| - s.name = 'AUFlagPhoneNumber' - s.version = '0.8.1' - s.summary = 'A formatted phone number UITextField with country flag picker.' - - # This description is used to generate tags and improve search results. - # * Think: What does it do? Why did you write it? What is the focus? - # * Try to keep it short, snappy and to the point. - # * Write the description between the DESC delimiters below. - # * Finally, don't worry about the indent, CocoaPods strips it! - - s.description = <<-DESC - AUFlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. - DESC - - s.homepage = 'https://github.com/Ku6ep/AUFlagPhoneNumber' - s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } - s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } - s.source = { :git => 'https://github.com/Ku6ep/FlagPhoneNumber.git', :tag => s.version.to_s } - - s.ios.deployment_target = '8.0' - s.source_files = 'Sources/**/*.swift' - s.resource_bundles = {'AUFlagPhoneNumber' => ['Sources/Resources/**/*']} - s.swift_version = '5.0' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } - - s.subspec 'libPhoneNumberiOS' do |ss| - ss.source_files = 'Sources/libPhoneNumber/**/*.{m,h}' - end -end From f7960022889533d79030b23b2d1803b048b5feb0 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 17:36:42 +0200 Subject: [PATCH 06/11] Add new podspec --- AUFlagPhoneNumber.podspec | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 AUFlagPhoneNumber.podspec diff --git a/AUFlagPhoneNumber.podspec b/AUFlagPhoneNumber.podspec new file mode 100644 index 00000000..21550453 --- /dev/null +++ b/AUFlagPhoneNumber.podspec @@ -0,0 +1,38 @@ +# +# Be sure to run `pod lib lint FlagPhoneNumber.podspec' to ensure this is a +# valid spec before submitting. +# +# Any lines starting with a # are optional, but their use is encouraged +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| + s.name = 'AUFlagPhoneNumber' + s.version = '0.8.1' + s.summary = 'A formatted phone number UITextField with country flag picker.' + + # This description is used to generate tags and improve search results. + # * Think: What does it do? Why did you write it? What is the focus? + # * Try to keep it short, snappy and to the point. + # * Write the description between the DESC delimiters below. + # * Finally, don't worry about the indent, CocoaPods strips it! + + s.description = <<-DESC + AUFlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. + DESC + + s.homepage = 'https://github.com/Ku6ep/AUFlagPhoneNumber' + s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } + s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } + s.source = { :git => 'https://github.com/Ku6ep/AUFlagPhoneNumber.git', :tag => s.version.to_s } + + s.ios.deployment_target = '8.0' + s.source_files = 'Sources/**/*.swift' + s.resource_bundles = {'AUFlagPhoneNumber' => ['Sources/Resources/**/*']} + s.swift_version = '5.0' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + + s.subspec 'libPhoneNumberiOS' do |ss| + ss.source_files = 'Sources/libPhoneNumber/**/*.{m,h}' + end +end From d12ca5ca1cc7d47cefa5a9fe89a553099a25d965 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 21:02:07 +0200 Subject: [PATCH 07/11] Fix changes --- AUFlagPhoneNumber.podspec | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 AUFlagPhoneNumber.podspec diff --git a/AUFlagPhoneNumber.podspec b/AUFlagPhoneNumber.podspec deleted file mode 100644 index 21550453..00000000 --- a/AUFlagPhoneNumber.podspec +++ /dev/null @@ -1,38 +0,0 @@ -# -# Be sure to run `pod lib lint FlagPhoneNumber.podspec' to ensure this is a -# valid spec before submitting. -# -# Any lines starting with a # are optional, but their use is encouraged -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html -# - -Pod::Spec.new do |s| - s.name = 'AUFlagPhoneNumber' - s.version = '0.8.1' - s.summary = 'A formatted phone number UITextField with country flag picker.' - - # This description is used to generate tags and improve search results. - # * Think: What does it do? Why did you write it? What is the focus? - # * Try to keep it short, snappy and to the point. - # * Write the description between the DESC delimiters below. - # * Finally, don't worry about the indent, CocoaPods strips it! - - s.description = <<-DESC - AUFlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. - DESC - - s.homepage = 'https://github.com/Ku6ep/AUFlagPhoneNumber' - s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } - s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } - s.source = { :git => 'https://github.com/Ku6ep/AUFlagPhoneNumber.git', :tag => s.version.to_s } - - s.ios.deployment_target = '8.0' - s.source_files = 'Sources/**/*.swift' - s.resource_bundles = {'AUFlagPhoneNumber' => ['Sources/Resources/**/*']} - s.swift_version = '5.0' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } - - s.subspec 'libPhoneNumberiOS' do |ss| - ss.source_files = 'Sources/libPhoneNumber/**/*.{m,h}' - end -end From 32774c63e743e54f27f725e556582861629a5410 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 21:02:29 +0200 Subject: [PATCH 08/11] Return original podspec --- FlagPhoneNumber.podspec | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 FlagPhoneNumber.podspec diff --git a/FlagPhoneNumber.podspec b/FlagPhoneNumber.podspec new file mode 100644 index 00000000..4264ce68 --- /dev/null +++ b/FlagPhoneNumber.podspec @@ -0,0 +1,38 @@ +# +# Be sure to run `pod lib lint FlagPhoneNumber.podspec' to ensure this is a +# valid spec before submitting. +# +# Any lines starting with a # are optional, but their use is encouraged +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| + s.name = 'FlagPhoneNumber' + s.version = '0.8.0' + s.summary = 'A formatted phone number UITextField with country flag picker.' + + # This description is used to generate tags and improve search results. + # * Think: What does it do? Why did you write it? What is the focus? + # * Try to keep it short, snappy and to the point. + # * Write the description between the DESC delimiters below. + # * Finally, don't worry about the indent, CocoaPods strips it! + + s.description = <<-DESC + FlagPhoneNumber is a phone number textfield that allows you to choose the country code thanks to a picker. It uses libPhoneNumber to format the number in the textfield according to country code. + DESC + + s.homepage = 'https://github.com/chronotruck/FlagPhoneNumber' + s.license = { :type => 'Apache License 2.0', :file => 'LICENSE' } + s.author = { 'Aurélien Grifasi' => 'aurelien.grifasi@chronotruck.com' } + s.source = { :git => 'https://github.com/chronotruck/FlagPhoneNumber.git', :tag => s.version.to_s } + + s.ios.deployment_target = '8.0' + s.source_files = 'Sources/**/*.swift' + s.resource_bundles = {'FlagPhoneNumber' => ['Sources/Resources/**/*']} + s.swift_version = '5.0' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + + s.subspec 'libPhoneNumberiOS' do |ss| + ss.source_files = 'Sources/libPhoneNumber/**/*.{m,h}' + end +end From 2a1b113b589e874e131d75e5b74a4964a1e27718 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 21:09:37 +0200 Subject: [PATCH 09/11] Make distance bigger --- Sources/FPNTextField.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index c7a58517..c8589051 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -152,7 +152,7 @@ open class FPNTextField: UITextField { var distanceFromFlag: CGFloat = 0.0 if #available(iOS 13, *) { - distanceFromFlag = -4.0 + distanceFromFlag = -8.0 } NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: distanceFromFlag).isActive = true From 5e248b9863296a38dd3e972172fca4db8f7ef418 Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Thu, 11 Jun 2020 21:16:30 +0200 Subject: [PATCH 10/11] Fix error --- Sources/FPNTextField.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index c8589051..6e9b8109 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -156,7 +156,6 @@ open class FPNTextField: UITextField { } NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: distanceFromFlag).isActive = true - NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .trailing, relatedBy: .equal, toItem: leftView, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .top, relatedBy: .equal, toItem: leftView, attribute: .top, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .bottom, relatedBy: .equal, toItem: leftView, attribute: .bottom, multiplier: 1, constant: 0).isActive = true From 0fb1525d24bbd894f24bf593fa2cab8be3f858aa Mon Sep 17 00:00:00 2001 From: Anton Umnitsyn Date: Wed, 17 Jun 2020 14:21:41 +0200 Subject: [PATCH 11/11] Fix wrong position. Add space via padding for text field --- Sources/FPNTextField.swift | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index 6e9b8109..9c760edc 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -19,6 +19,7 @@ open class FPNTextField: UITextField { private var flagWidthConstraint: NSLayoutConstraint? private var flagHeightConstraint: NSLayoutConstraint? + private var padding = UIEdgeInsets(top: 0, left: 70, bottom: 0, right: 5) /// The size of the leftView private var leftViewSize: CGSize { @@ -48,6 +49,20 @@ open class FPNTextField: UITextField { } } + override open func textRect(forBounds bounds: CGRect) -> CGRect { + super.textRect(forBounds: bounds) + return bounds.inset(by: padding) + } + + override open func placeholderRect(forBounds bounds: CGRect) -> CGRect { + super.placeholderRect(forBounds: bounds) + return bounds.inset(by: padding) + } + + override open func editingRect(forBounds bounds: CGRect) -> CGRect { + super.editingRect(forBounds: bounds) + return bounds.inset(by: padding) + } /// Present in the placeholder an example of a phone number according to the selected country code. /// If false, you can set your own placeholder. Set to true by default. @objc open var hasPhoneNumberExample: Bool = true { @@ -150,12 +165,7 @@ open class FPNTextField: UITextField { NSLayoutConstraint(item: flagButton, attribute: .centerY, relatedBy: .equal, toItem: leftView, attribute: .centerY, multiplier: 1, constant: 0).isActive = true - var distanceFromFlag: CGFloat = 0.0 - if #available(iOS 13, *) { - distanceFromFlag = -8.0 - } - - NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: distanceFromFlag).isActive = true + NSLayoutConstraint(item: phoneCodeTextField, attribute: .leading, relatedBy: .equal, toItem: flagButton, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .trailing, relatedBy: .equal, toItem: leftView, attribute: .trailing, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .top, relatedBy: .equal, toItem: leftView, attribute: .top, multiplier: 1, constant: 0).isActive = true NSLayoutConstraint(item: phoneCodeTextField, attribute: .bottom, relatedBy: .equal, toItem: leftView, attribute: .bottom, multiplier: 1, constant: 0).isActive = true @@ -382,6 +392,7 @@ open class FPNTextField: UITextField { if let phoneCode = selectedCountry?.phoneCode { phoneCodeTextField.text = phoneCode + padding = UIEdgeInsets(top: 0, left: CGFloat(70 + (phoneCode.count-2) * 10), bottom: 0, right: 5) } if hasPhoneNumberExample == true {