Code Monkey home page Code Monkey logo

countrycode's Introduction

CountryPicker

Swift Package Manager compatible Build Status Platform Swift version Swift version Beerpay

Picker code Swift 3 / 4 / 5.

Example

To run the example project, clone the repo, and run pod install from the Example directory first. 1

Usage

Make your UIPickerView a class of CountryPicker, set its countryPickerDelegate and implement its countryPhoneCodePicker method.

Example:

import CountryPicker

class ViewController: UIViewController, CountryPickerDelegate {

    @IBOutlet weak var picker: CountryPicker!
   
    
    override func viewDidLoad() {
        super.viewDidLoad()
       //get current country
        let locale = Locale.current
        let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String?
        //init Picker
        picker.displayOnlyCountriesWithCodes = ["DK", "SE", "NO", "DE"] //display only
        picker.exeptCountriesWithCodes = ["RU"] //exept country
        let theme = CountryViewTheme(countryCodeTextColor: .white, countryNameTextColor: .white, rowBackgroundColor: .black, showFlagsBorder: false)        //optional for UIPickerView theme changes
        picker.theme = theme //optional for UIPickerView theme changes
        picker.countryPickerDelegate = self
        picker.showPhoneNumbers = true
        picker.setCountry(code!)

    }
    
    // a picker item was selected
    func countryPhoneCodePicker(_ picker: CountryPicker, didSelectCountryWithName name: String, countryCode: String, phoneCode: String, flag: UIImage) {
       //pick up anythink
      code.text = phoneCode
    }

}

Integration

CocoaPods (iOS 8+, OS X 10.9+)

CountryPicker is available through CocoaPods. To install

Swift 4-5 (Xcode 10+) pod 'CountryPickerSwift', '1.8'

Swift 3.1 (Xcode 9) pod 'CountryPickerSwift', '1.7'

Swift 3.0+ (Xcode 8) pod 'CountryPickerSwift', '1.4.4'

it, simply add the following line to your 'Podfile':

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod 'CountryPickerSwift'
end

Swift Package Manager

You can use The Swift Package Manager to install CountryPicker by adding the proper description to your Package.swift file:

Add package:     https://github.com/4taras4/CountryCode

Note that the Swift Package Manager is still in early design and development, for more information checkout its GitHub Page

Manually

To use this library in your project manually just drag and drop CountryPicker folder to your project.

Author

4taras4, [email protected]

License

CountryPicker is available under the MIT license. See the LICENSE file for more info. release-link

Donate

Donation Bitcoin 141Q3KduSqvTtMbrU6YouSErDBh1SpiLrL

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

countrycode's People

Contributors

4taras4 avatar ehsanmashhadi avatar juanj avatar kedar-27 avatar madhavajay avatar melmox avatar omerawastaken avatar ppeszko avatar sadiq81 avatar sauravexodus avatar senseiphonex avatar swiftkicker avatar synthemesc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

countrycode's Issues

Initial create is very slow

Hey,

I'm using the CountryCode picker after tapping on a button, but it seems to take ages (at least 5 seconds) on it's initial var countryPicker = CountryPicker() call. Any ideas how to accelerate that?

var countryPicker = CountryPicker()
countryPicker.frame = CGRect(x: 0, y: self.keyboardToolbar.frame.size.height, width: self.frame.size.width, height: pickerViewHeight)
countryPicker.showPhoneNumbers = true
countryPicker.countryPickerDelegate = self
countryPicker.backgroundColor = UIColor.vrPaleGreyColor()
countryPicker.setCountry(((Locale.current as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String?)!)

SPM - Failed to resolve dependencies

When adding this repo to swift package manger, I get the following error :
Failed to resolve dependencies because CountryCode >=1.4.3 contains incompatible tools version and root depends on CountryCode 1.8.2..<1.9.0, version solving failed.

Language Code Missing

I wanted to add a language switching feature on my application, and I needed the language code of each country. If there are other ways of getting the language code or changing the language of the application from the country picker please notify me.

Privacy Manifest

Hello,

At WWDC23 Apple announced that apps and SDKs that make use of certain "required reason" APIs etc will need to provide a privacy manifest.
Does CountryCode need to include this manifest?

Here are some useful references:

https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_data_use_in_privacy_manifests
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
https://developer.apple.com/videos/play/wwdc2023/10060/

Thanks

picking and click bug

Hi

thank you for great repo. i added this repo to my app, but i found mini bug.

i just picking to list and touch current selected object. wow selected first country.

Coloring

Hey guys. Awesome library, however I have one little problem.

I added it as a inputView to make it appear like keyboard. But like this it is impossible to change it's color. Do you know any solution for this?

You can check out the detailed problem description from here.

Load Bundle Crash

Inside

fileprivate func loadViewFromNib() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
        let nibView = nib.instantiate(withOwner: self, options: nil).first as! UIView
        
        return nibView
    }

This error occures:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/F064407E-A951-47C1-8C3C-AD1938DD885F/MyApp.app> (loaded)' with name 'CountryView''


Countries order

Hey,

I have started using Country Picker and I have encountered two issues. I hope we can solve this.

  1. I am filtering countries in pickerView, so I have got Austria, Germany, Poland, Switzerland. Is there any way I can change order of these items? I guess it's preset alphabetically. I would like to begin with Germany.
  2. When I tap on a particular country in the row, I get phoneCode from the first item in that array. I mean, I have swiped on Switzerland, it gives me +41 as it should and when I tap on that Switzerland row I get phoneCode from Austria (+43). Same with others countries beside Austria which is first in that array.

Here is my code:

func countryPhoneCodePicker(_ picker: CountryPicker, didSelectCountryWithName name: String, 
     countryCode: String, phoneCode: String, flag: UIImage) {
    countryCodeButton.setTitle(phoneCode, for: .normal)
    countryImage.image = flag
}


 func initPicker() {
    let locale = Locale.current
    guard let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String? 
   else {
        return
      }

    countryPicker.displayOnlyCountriesWithCodes = StringConstants.codes.countryCodes
    countryPicker.countryPickerDelegate = self
    countryPicker.showPhoneNumbers = true
    countryPicker.setCountry(code)
}

Wrong result when tapping on already selected row

Currenlty delegate recevies wrong values, when users taps on selected row in picker.
Delegate receives data for country 0, but app expects to see data for country actually tapped (in selected row)

No access to the CountryPicker using SPM

Hello.

I am trying to integrate a library using the Swift Package Manager from the master branch, everything looks good, but there is no way to access the source files for CountryPicker, only for the dummy CountryCode struct.

Crash

In some devices in this line crash reported
CountryPicker.swift line 221

 resultView.setup(countries[row])

I generated this with scrolling the app to the top and bottom and select a country (do this scenario several times)

Crash app when use SPM 1.8.4

After add SPM follow recommend
But xcode 14 application crash when set delegate, datasource
Can you resolve issues and update?
Thanks!

Crash while building release version

After updating to 1.7.3 I got this crash when building my app in release mode:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/3232DF58-CCEB-491A-8387-7100A0D31587/fototax.app/Frameworks/CountryPicker.framework> (loaded)' with name 'CountryView''

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.