Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CountryPicker/CountryPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

@protocol CountryPickerDelegate <UIPickerViewDelegate>

- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code;
- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code flag:(UIImage *)flag;

@end

Expand All @@ -76,5 +76,5 @@
- (void)setSelectedCountryCode:(NSString *)countryCode animated:(BOOL)animated;
- (void)setSelectedCountryName:(NSString *)countryName animated:(BOOL)animated;
- (void)setSelectedLocale:(NSLocale *)locale animated:(BOOL)animated;

- (UIImage *)getSelectedFlag:(NSInteger)row;
@end
24 changes: 17 additions & 7 deletions CountryPicker/CountryPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ - (NSLocale *)selectedLocale
return nil;
}

- (UIImage *)getSelectedFlag:(NSInteger)row
{
NSString *imagePath = [NSString stringWithFormat:@"CountryPicker.bundle/%@", [[self class] countryCodes][(NSUInteger) row]];
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;
}

#pragma mark -
#pragma mark UIPicker

Expand Down Expand Up @@ -242,12 +254,7 @@ - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger
}

((UILabel *)[view viewWithTag:1]).text = [[self class] countryNames][(NSUInteger)row];
NSString *imagePath = [NSString stringWithFormat:@"CountryPicker.bundle/%@", [[self class] countryCodes][(NSUInteger) row]];
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];
UIImage *image = [self getSelectedFlag:row];
((UIImageView *)[view viewWithTag:2]).image = image;


Expand All @@ -258,8 +265,11 @@ - (void)pickerView:(__unused UIPickerView *)pickerView
didSelectRow:(__unused NSInteger)row
inComponent:(__unused NSInteger)component
{

UIImage *image = [self getSelectedFlag:row];

__strong id<CountryPickerDelegate> strongDelegate = delegate;
[strongDelegate countryPicker:self didSelectCountryWithName:self.selectedCountryName code:self.selectedCountryCode];
[strongDelegate countryPicker:self didSelectCountryWithName:self.selectedCountryName code:self.selectedCountryCode flag:image];
}

@end
2 changes: 2 additions & 0 deletions Examples/CountryPickerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
01D39FCD14E60FBC002FC9B1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist";
Expand All @@ -367,6 +368,7 @@
01D39FCE14E60FBC002FC9B1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist";
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01D39FAD14E60FBC002FC9B1"
BuildableName = "CountryPickerDemo.app"
BlueprintName = "CountryPickerDemo"
ReferencedContainer = "container:CountryPickerDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01D39FAD14E60FBC002FC9B1"
BuildableName = "CountryPickerDemo.app"
BlueprintName = "CountryPickerDemo"
ReferencedContainer = "container:CountryPickerDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01D39FAD14E60FBC002FC9B1"
BuildableName = "CountryPickerDemo.app"
BlueprintName = "CountryPickerDemo"
ReferencedContainer = "container:CountryPickerDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01D39FAD14E60FBC002FC9B1"
BuildableName = "CountryPickerDemo.app"
BlueprintName = "CountryPickerDemo"
ReferencedContainer = "container:CountryPickerDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CountryPickerDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>01D39FAD14E60FBC002FC9B1</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
1 change: 1 addition & 0 deletions Examples/CountryPickerDemo/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

@property (nonatomic, strong) IBOutlet UILabel *nameLabel;
@property (nonatomic, strong) IBOutlet UILabel *codeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *flagView;

@end
3 changes: 2 additions & 1 deletion Examples/CountryPickerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ @implementation ViewController

@synthesize nameLabel, codeLabel;

- (void)countryPicker:(__unused CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code
- (void)countryPicker:(__unused CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code flag:(UIImage *)flag
{
self.nameLabel.text = name;
self.codeLabel.text = code;
self.flagView.image = flag;
}

@end
Loading