Giter VIP home page Giter VIP logo

nicklockwood / countrypicker Goto Github PK

View Code? Open in Web Editor NEW
740.0 740.0 153.0 863 KB

CountryPicker is a custom UIPickerView subclass that provides an iOS control allowing a user to select a country from a list. It can optionally display a flag next to each country name, and the library includes a set of 249 high-quality, public domain flag images from FAMFAMFAM (http://www.famfamfam.com/lab/icons/flags/) that have been painstakingly re-named by country code to work with the library.

Home Page: http://charcoaldesign.co.uk/source/cocoa#countrypicker

License: Other

Objective-C 100.00%

countrypicker's People

Contributors

andreyvit avatar erichedstrom avatar hearther avatar nicklockwood avatar soffes 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

countrypicker's Issues

Please add imageForCountryCode

I made a small change to your code (CountryPicker.m, v1.3)

starting in line 230 added the function:

-(UIImage*)imageForCountryCode:(NSString*)countryCode
{
    NSString *imagePath = [NSString stringWithFormat:@"CountryPicker.bundle/%@", countryCode];
    UIImage *image;
    if ([[UIImage class] respondsToSelector:@selector(imageNamed:inBundle:compatibleWithTraitCollection:)])
    {
        image = [UIImage imageNamed:imagePath inBundle:[NSBundle bundleForClass:[CountryPicker class]] compatibleWithTraitCollection:nil];
    }
    else
    {
        image = [UIImage imageNamed:imagePath];
    }

    return image;
}

So by subclassing, one can add flags for extra added nations. I needed to add nations such as Soviet Union to collect people's country of birth.

Then changed the function at row 230:

- (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger)row
          forComponent:(__unused NSInteger)component reusingView:(UIView *)view
{
    if (!view)
    {
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 30)];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(35, 3, 245, 24)];
        label.backgroundColor = [UIColor clearColor];
        label.tag = 1;
        if (self.labelFont)
        {
            label.font = self.labelFont;
        }
        [view addSubview:label];
        
        UIImageView *flagView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 24, 24)];
        flagView.contentMode = UIViewContentModeScaleAspectFit;
        flagView.tag = 2;
        [view addSubview:flagView];
    }

    ((UILabel *)[view viewWithTag:1]).text = [[self class] countryNames][(NSUInteger)row];  

    UIImage *image = [self imageForCountryCode:[[self class] countryCodes][(NSUInteger) row]];

    ((UIImageView *)[view viewWithTag:2]).image = image;
    return view;
}

Of course the imageForCountryCode API needs to be added to the interface.
Could you please insert this change in future updates, or provide some mechanism to add flags to extra added nations?
Thanks, David

Issue with iOS8

NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];

countryName is always nil in iOS 8 (beta 2)

Compile time is very slow

First of all, I want to say this is a VERY nice and easy to use plugin. No matter what! Now, after adding CountryPicker as a pod in my project, my time to compile and launch the simulator went from 3-4 seconds, to 8-10 seconds. I removed it, and went back to 3-4 seconds. Any ideas as to why?!

Thanks!

Request: Don't localized country name

I need the country name to always be in English. (Disregard localization and i18n)
(Localized country name is a great feature but I would like to have an option to define single permanent language).
Is it possible with current code? Can you make it available?
Great picker - Thanks!

iOS 8

Flag not showing on iOS 8

Support for Swift Package Manager

As of SPM arrival with Xcode 11 a lot of project are being migrated from carthage and pods package architectures to Swift Package Manager. Is there any plans to add support for SPM for this library?

Cannot display flag image

In Readme you say:
If you want to use the flag icons, drag the CountryPicker.bundle folder in also.
but even if I did it, I cannot see flag. Can you tell me why?
I am working in Version 5.1.1 (5B1008).
Please help me.
Thanks.

Wrong country code for KOSOVO = 0

Hi,

Randomly check country code and found a issue(I don't know it's only for me or others too). For country KOSOVO have country code is "0" for all other it's working fine.

Thanks.

reloadAllComponents not working

I'm trying to filter the country list modifying the countryNamesByCode, as mentioned by the documentation. But I need to refresh the elements, with a new _countryNamesByCode (which i've modified). When I use the pickerView method reloadAllComponents, the picker don't suffer any modification.
But if I try to do the same logic with the countryCodes method and static variable, i'm able to modify the list but the flags aren't modified...

kind of need some help here...
thanks

How do I get initial information of country without using onSelect?

I have a component that initialises the CountryPicker with a countryCode. Now I want to find out the callingCode of the country without having the user actually select anything.

E.g.

  const [cca2, setCca2] = useState<CountryCode>('AU');

<CountryPicker
          containerButtonStyle={{marginBottom: 10}}
          onSelect={(value) => selectCountry(value)}
          translation="common"
          countryCode={cca2}
        />

How do I get country.callingCode at the start before the user has interacted with the picker?

Change Localized

I have an app that user can change language. But when i change the language, countrypicker did not. It only change when i close and open again the app. Is there something that i can explicit change the language?

Custom country order

Hi Nick,
Thanks for sharing CountryPicker.

I have a question regarding the order of the countries. What if I want to have "United States" as the first country in list, without simply forking your repo (which I did here: https://github.com/instaply/CountryPicker) ?

I tried with subclassing but the subclass doesn't see the static variables :(
And I guess it will be the same for category.

Any suggestion?
Your help will be much appreciated.
Thx,
Arnaud

Proposal

It's not rare, when you need countries for their phone code number. Is it available now? or will it be supported in the future?

Cocoapods integration

Can this be integrated with cocoapods? if it is already, can the readme file installation section mentions it? Thanks in advance (:

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.