diff --git a/CountryPicker/CountryPicker.h b/CountryPicker/CountryPicker.h index 9967b230..cdbeb544 100644 --- a/CountryPicker/CountryPicker.h +++ b/CountryPicker/CountryPicker.h @@ -53,7 +53,7 @@ @protocol CountryPickerDelegate -- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code; +- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code flag:(UIImage *)flag; @end @@ -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 diff --git a/CountryPicker/CountryPicker.m b/CountryPicker/CountryPicker.m index db484b88..ab40d049 100644 --- a/CountryPicker/CountryPicker.m +++ b/CountryPicker/CountryPicker.m @@ -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 @@ -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; @@ -258,8 +265,11 @@ - (void)pickerView:(__unused UIPickerView *)pickerView didSelectRow:(__unused NSInteger)row inComponent:(__unused NSInteger)component { + + UIImage *image = [self getSelectedFlag:row]; + __strong id strongDelegate = delegate; - [strongDelegate countryPicker:self didSelectCountryWithName:self.selectedCountryName code:self.selectedCountryCode]; + [strongDelegate countryPicker:self didSelectCountryWithName:self.selectedCountryName code:self.selectedCountryCode flag:image]; } @end diff --git a/Examples/CountryPickerDemo.xcodeproj/project.pbxproj b/Examples/CountryPickerDemo.xcodeproj/project.pbxproj index 2537ce64..826d1814 100644 --- a/Examples/CountryPickerDemo.xcodeproj/project.pbxproj +++ b/Examples/CountryPickerDemo.xcodeproj/project.pbxproj @@ -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"; @@ -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"; diff --git a/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/xcuserdata/tovarna.xcuserdatad/UserInterfaceState.xcuserstate b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/xcuserdata/tovarna.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..3d345d94 Binary files /dev/null and b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/xcuserdata/tovarna.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/CountryPickerDemo.xcscheme b/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/CountryPickerDemo.xcscheme new file mode 100644 index 00000000..7408cefa --- /dev/null +++ b/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/CountryPickerDemo.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/xcschememanagement.plist b/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..c1971e2b --- /dev/null +++ b/Examples/CountryPickerDemo.xcodeproj/xcuserdata/tovarna.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + CountryPickerDemo.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 01D39FAD14E60FBC002FC9B1 + + primary + + + + + diff --git a/Examples/CountryPickerDemo/ViewController.h b/Examples/CountryPickerDemo/ViewController.h index fbe754bb..1f779121 100644 --- a/Examples/CountryPickerDemo/ViewController.h +++ b/Examples/CountryPickerDemo/ViewController.h @@ -13,5 +13,6 @@ @property (nonatomic, strong) IBOutlet UILabel *nameLabel; @property (nonatomic, strong) IBOutlet UILabel *codeLabel; +@property (weak, nonatomic) IBOutlet UIImageView *flagView; @end diff --git a/Examples/CountryPickerDemo/ViewController.m b/Examples/CountryPickerDemo/ViewController.m index f07e9e95..7cf71521 100644 --- a/Examples/CountryPickerDemo/ViewController.m +++ b/Examples/CountryPickerDemo/ViewController.m @@ -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 diff --git a/Examples/CountryPickerDemo/en.lproj/ViewController.xib b/Examples/CountryPickerDemo/en.lproj/ViewController.xib index 87efdfb5..0ad49c3b 100644 --- a/Examples/CountryPickerDemo/en.lproj/ViewController.xib +++ b/Examples/CountryPickerDemo/en.lproj/ViewController.xib @@ -1,259 +1,51 @@ - - - - 1280 - 11C74 - 1938 - 1138.23 - 567.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 933 - - - IBUIPickerView - IBUIView - IBUILabel - IBProxyObject - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 290 - {{0, 244}, {320, 216}} - - - - _NS:650 - IBCocoaTouchFramework - YES - - - - 292 - {{61, 50}, {198, 21}} - - - - _NS:328 - NO - YES - 7 - NO - IBCocoaTouchFramework - Name - - 1 - MCAwIDAAA - - - 1 - 10 - 1 - - 1 - 17 - - - Helvetica - 17 - 16 - - - - - 292 - {{136, 105}, {48, 21}} - - - - _NS:328 - NO - YES - 7 - NO - IBCocoaTouchFramework - Code - - - 1 - 10 - 1 - - - - - {{0, 20}, {320, 460}} - - - - - 3 - MC43NQA - - 2 - - - NO - - IBCocoaTouchFramework - - - - - - - view - - - - 7 - - - - nameLabel - - - - 13 - - - - codeLabel - - - - 14 - - - - delegate - - - - 9 - - - - - - 0 - - - - - - -1 - - - File's Owner - - - -2 - - - - - 6 - - - - - - - - - - 11 - - - - - 10 - - - - - 8 - - - - - - - ViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - CountryPicker - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 14 - - - - - CountryPicker - UIPickerView - - IBProjectSource - ./Classes/CountryPicker.h - - - - ViewController - UIViewController - - UILabel - UILabel - - - - codeLabel - UILabel - - - nameLabel - UILabel - - - - IBProjectSource - ./Classes/ViewController.h - - - - - 0 - IBCocoaTouchFramework - YES - 3 - 933 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +