Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add imageForCountryCode #42

Open
FrizzTheSnail opened this issue Jul 20, 2017 · 0 comments
Open

Please add imageForCountryCode #42

FrizzTheSnail opened this issue Jul 20, 2017 · 0 comments

Comments

@FrizzTheSnail
Copy link

FrizzTheSnail commented Jul 20, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant