ADCountryPicker 2.1.0

ADCountryPicker 2.1.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布上次发布2019年2月
SPM支持 SPM

Amila Dimantha 维护。



ADCountryPicker

ADCountryPicker 是一个适用于 iOS8+ 的国家选择控制器,支持搜索。国家列表基于 ISO 3166 国家代码标准 (http://en.wikipedia.org/wiki/ISO_3166-1)。此外,该库还包括一组 250 个公有领域国旗图片。

选择器提供

  • 国家名称
  • 国家代码 - ISO 3166
  • 国际电话区号
  • 国旗

屏幕截图

alt tag alt tag alt tag alt tag

注意:当前位置取决于 iPhone 的当前区域

安装

ADCountryPicker 通过 CocoaPods 提供,要安装它,只需在 Podfile 中添加以下行

Swift 4 >

use_frameworks!
 pod 'ADCountryPicker', '~> 2.1.0'

Swift 3

use_frameworks!
pod 'ADCountryPicker', '~> 1.0.5'

从 UIViewController 中推送 ADCountryPicker

let picker = ADCountryPicker(style: .grouped)
navigationController?.pushViewController(picker, animated: true)

从 UIViewController 中展示 ADCountryPicker

let picker = ADCountryPicker()
let pickerNavigationController = UINavigationController(rootViewController: picker)
self.present(pickerNavigationController, animated: true, completion: nil)

ADCountryPicker 属性

/// delegate
picker.delegate = self

/// Optionally, set this to display the country calling codes after the names
picker.showCallingCodes = true

/// Flag to indicate whether country flags should be shown on the picker. Defaults to true
picker.showFlags = true
    
/// The nav bar title to show on picker view
picker.pickerTitle = "Select a Country"
    
/// The default current location, if region cannot be determined. Defaults to US
picker.defaultCountryCode = "US"

/// Flag to indicate whether the defaultCountryCode should be used even if region can be deteremined. Defaults to false
picker.forceDefaultCountryCode = false

/// The text color of the alphabet scrollbar. Defaults to black
picker.alphabetScrollBarTintColor = UIColor.black
    
/// The background color of the alphabet scrollar. Default to clear color
picker.alphabetScrollBarBackgroundColor = UIColor.clear
    
/// The tint color of the close icon in presented pickers. Defaults to black
picker.closeButtonTintColor = UIColor.black
    
/// The font of the country name list
picker.font = UIFont(name: "Helvetica Neue", size: 15)
    
/// The height of the flags shown. Default to 40px
picker.flagHeight = 40
    
/// Flag to indicate if the navigation bar should be hidden when search becomes active. Defaults to true
picker.hidesNavigationBarWhenPresentingSearch = true
    
/// The background color of the searchbar. Defaults to lightGray
picker.searchBarBackgroundColor = UIColor.lightGray

ADCountryPickerDelegate 协议

func countryPicker(picker: ADCountryPicker, didSelectCountryWithName name: String, code: String) {
        print(code)
}

func countryPicker(picker: ADCountryPicker, didSelectCountryWithName name: String, code: String, dialCode: String) {
        print(dialCode)
}

Closure

// or closure
picker.didSelectCountryClosure = { name, code in
        print(code)
}

picker.didSelectCountryWithCallingCodeClosure = { name, code, dialCode in
        print(dialCode)
}

辅助函数

/// Returns the country flag for the given country code
///
/// - Parameter countryCode: ISO code of country to get flag for
/// - Returns: the UIImage for given country code if it exists
let flagImage =  picker.getFlag(countryCode: code)


/// Returns the country name for the given country code
///
/// - Parameter countryCode: ISO code of country to get dialing code for
/// - Returns: the country name for given country code if it exists
let countryName =  picker.getCountryName(countryCode: code)


/// Returns the country dial code for the given country code
///
/// - Parameter countryCode: ISO code of country to get dialing code for
/// - Returns: the dial code for given country code if it exists
let dialingCode =  picker.getDialCode(countryCode: code)

作者

Amila Dimantha, [email protected]

基于 @mustafaibrahim989 的工作。

备注

适用于 iOS 8 及以上版本。

许可证

ADCountryPicker 基于 MIT 许可证提供。更多信息请参阅 LICENSE 文件。