Skip to content

Commit

Permalink
Updated for 1.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Sep 30, 2016
1 parent 42214d7 commit ecb0dab
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 108 deletions.
15 changes: 8 additions & 7 deletions CountryPicker.podspec.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "CountryPicker",
"version": "1.2.3",
"license": "zlib",
"version": "1.3",
"license": {
"type": "zlib",
"file": "LICENCE.md"
},
"summary": "CountryPicker is a custom UIPickerView subclass that provides an iOS control allowing a user to select a country from a list.",
"homepage": "http://github.com/nicklockwood/CountryPicker",
"authors": {
"Nick Lockwood": "http://charcoaldesign.co.uk/"
},
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/CountryPicker.git",
"tag": "1.2.3"
"tag": "1.3"
},
"platforms": {
"ios": "4.3"
"ios": "5.0"
},
"source_files": "CountryPicker/CountryPicker.{h,m}",
"resources": "CountryPicker/CountryPicker.bundle",
Expand Down

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

59 changes: 41 additions & 18 deletions CountryPicker/CountryPicker.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// CountryPicker.h
//
// Version 1.2.3
// Version 1.3
//
// Created by Nick Lockwood on 25/04/2011.
// Copyright 2011 Charcoal Design
// Copyright © 2011 Nick Lockwood. All rights reserved.
//
// Distributed under the permissive zlib License
// Get the latest version from here:
Expand Down Expand Up @@ -35,16 +35,6 @@
// 3. This notice may not be removed or altered from any source distribution.
//


#import <Availability.h>
#undef weak_delegate
#if __has_feature(objc_arc_weak)
#define weak_delegate weak
#else
#define weak_delegate unsafe_unretained
#endif


#import <UIKit/UIKit.h>


Expand All @@ -53,28 +43,61 @@

@protocol CountryPickerDelegate <UIPickerViewDelegate>

/// This method is called whenever a country is selected in the picker.
- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code;

@end


@interface CountryPicker : UIPickerView

+ (NSArray *)countryNames;
+ (NSArray *)countryCodes;
+ (NSDictionary *)countryNamesByCode;
+ (NSDictionary *)countryCodesByName;
/// Returns an array of all country names in alphabetical order.
+ (NSArray<NSString *> *)countryNames;

/// Returns an array of all country codes. The codes are sorted by country
/// name, and their indices match the indices of their respective country name
/// in the `countryNames`list, but note that this means that the codes
/// themselves are not sorted alphabetically.
+ (NSArray<NSString *> *)countryCodes;

/// Returns a dictionary of country names, keyed by country code.
+ (NSDictionary<NSString *, NSString *> *)countryNamesByCode;

@property (nonatomic, weak_delegate) id<CountryPickerDelegate> delegate;
/// Returns a dictionary of country codes, keyed by country name.
+ (NSDictionary<NSString *, NSString *> *)countryCodesByName;

/// The delegate. This implements the CountryPickerDelegate protocol,
/// and is notified when a country is selected.
@property (nonatomic, weak) id<CountryPickerDelegate> delegate;

/// The currently selected country name. This is a read-write property,
/// so it can be used to set the picker value. Setting the picker to a country
/// name that does not appear in the `countryNames` array has no effect.
@property (nonatomic, copy) NSString *selectedCountryName;

/// The currently selected country code. This is a read-write property, so it
/// can be used to set the picker value. Setting the picker to a country code
/// that does not appear in the `countryCodes` array has no effect.
@property (nonatomic, copy) NSString *selectedCountryCode;

/// This is a convenience property to set/get the selected country using a
/// locale. The picker will automatically select the correct country based on
/// the local. To default the picker to the current device locale, you can say
/// `picker.selectedLocale = [NSLocale currentLocale];`
@property (nonatomic, copy) NSLocale *selectedLocale;

@property (nonatomic, strong) UIFont *labelFont;
/// The font used by the labels in the picker. Set this to change the font.
@property (nonatomic, copy) UIFont *labelFont;

/// These method allows you to set the current country code.
/// It works exactly like the equivalent property setter, but has an optional
/// animated parameter to make the picker scroll smoothly to the selected country.
- (void)setSelectedCountryCode:(NSString *)countryCode animated:(BOOL)animated;

/// As above, but for the selected country name.
- (void)setSelectedCountryName:(NSString *)countryName animated:(BOOL)animated;

/// As above but for the selected locale.
- (void)setSelectedLocale:(NSLocale *)locale animated:(BOOL)animated;

@end
32 changes: 20 additions & 12 deletions CountryPicker/CountryPicker.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// CountryPicker.m
//
// Version 1.2.3
// Version 1.3
//
// Created by Nick Lockwood on 25/04/2011.
// Copyright 2011 Charcoal Design
// Copyright © 2011 Nick Lockwood. All rights reserved.
//
// Distributed under the permissive zlib License
// Get the latest version from here:
Expand Down Expand Up @@ -37,9 +37,8 @@

#import "CountryPicker.h"


#pragma GCC diagnostic ignored "-Wselector"
#pragma GCC diagnostic ignored "-Wgnu"
#pragma clang diagnostic ignored "-Wselector"
#pragma clang diagnostic ignored "-Wgnu"


#import <Availability.h>
Expand All @@ -55,15 +54,15 @@ @interface CountryPicker () <UIPickerViewDelegate, UIPickerViewDataSource>

@implementation CountryPicker

//doesn't use _ prefix to avoid name clash with superclass
@synthesize delegate;
// delegate doesn't use _ prefix to avoid name clash with superclass
@synthesize delegate, labelFont = _labelFont;

+ (NSArray *)countryNames
{
static NSArray *_countryNames = nil;
if (!_countryNames)
{
_countryNames = [[[[self countryNamesByCode] allValues] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] copy];
_countryNames = [[[self countryNamesByCode].allValues sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] copy];
}
return _countryNames;
}
Expand Down Expand Up @@ -207,6 +206,12 @@ - (NSLocale *)selectedLocale
return nil;
}

- (void)setLabelFont:(UIFont *)labelFont
{
_labelFont = labelFont;
[self reloadComponent:0];
}

#pragma mark -
#pragma mark UIPicker

Expand All @@ -217,7 +222,7 @@ - (NSInteger)numberOfComponentsInPickerView:(__unused UIPickerView *)pickerView

- (NSInteger)pickerView:(__unused UIPickerView *)pickerView numberOfRowsInComponent:(__unused NSInteger)component
{
return (NSInteger)[[[self class] countryCodes] count];
return (NSInteger)[[self class] countryCodes].count;
}

- (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger)row
Expand All @@ -230,7 +235,8 @@ - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(35, 3, 245, 24)];
label.backgroundColor = [UIColor clearColor];
label.tag = 1;
if (self.labelFont) {
if (self.labelFont)
{
label.font = self.labelFont;
}
[view addSubview:label];
Expand All @@ -245,12 +251,14 @@ - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger
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];
}
((UIImageView *)[view viewWithTag:2]).image = image;


return view;
}

Expand Down
11 changes: 10 additions & 1 deletion Examples/CountryPickerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
01D39FA514E60FBB002FC9B1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0600;
LastUpgradeCheck = 0800;
};
buildConfigurationList = 01D39FA814E60FBB002FC9B1 /* Build configuration list for PBXProject "CountryPickerDemo" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -227,6 +227,7 @@
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
Expand All @@ -235,14 +236,17 @@
CLANG_WARN_OBJC_RECEIVER_WEAK = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -300,6 +304,7 @@
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
Expand All @@ -308,13 +313,15 @@
CLANG_WARN_OBJC_RECEIVER_WEAK = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_SHORT_ENUMS = YES;
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
Expand Down Expand Up @@ -355,6 +362,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WARNING_CFLAGS = (
"-Wall",
Expand All @@ -370,6 +378,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WARNING_CFLAGS = (
"-Wall",
Expand Down

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

2 changes: 1 addition & 1 deletion Examples/CountryPickerDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @implementation AppDelegate

- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(__unused NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
Expand Down
2 changes: 1 addition & 1 deletion Examples/CountryPickerDemo/CountryPickerDemo-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleIconFiles</key>
<array/>
<key>CFBundleIdentifier</key>
<string>com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion LICENCE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CountryPicker

Version 1.2.3, December 4th, 2014
Version 1.3, September 30th, 2016

Copyright (C) 2011 Charcoal Design

Expand Down
Loading

0 comments on commit ecb0dab

Please sign in to comment.