一、简介
该项目集成了三种类型的城市选择器:
- 1、XXCityPickerView 省市区,可以分级:1省 2省-市 3省-市-区
- 2、SQSelectAddress 省市区乡/镇,页面跳转
- 3、RattanCityPicker 省市区,包含邮编地址,开放多个属性设置的接口
##二、XXCityPickerView使用
####1、从该项目导入【XXCityPickerView】文件包
####2、 导入系统库 :libsqlite3.tbd
####3、方法实现
#import "XXCityPickerView.h"
@interface ViewController ()<XXCityPickerViewDelegate>
@property(nonatomic,strong)XXCityPickerView *cityPicker;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
///方法调用
-(void)clickAction{
[self cityPicker];
}
- (XXCityPickerView *)cityPicker{
if (_cityPicker == nil){
// 初始化 设置类别 1省 2省-市 3省-市-区
_cityPicker = [[XXCityPickerView alloc]initWithComponents:3];
// 设置代理
_cityPicker.delegate = self;
[self.view addSubview:_cityPicker];
}
return _cityPicker;
}
####4、代理实现
// ---- 【XXCityPickerViewDelegate】
// 取消
- (void)XXCityPickerViewLeftAction{
[self removeCityPickerView];
}
// 完成
- (void)XXCityPickerViewRightAction:(XXCityPickerView *)picker andCity:(NSString *)city andData:(NSMutableDictionary *)dic{
[self removeCityPickerView];
NSLog(@"???XXCityPickerView:\n city= %@ dic= %@",city,dic);
}
-(void)removeCityPickerView{
if (_cityPicker) {
[_cityPicker removeFromSuperview];
_cityPicker = nil;
}
}
##三、SQSelectAddress使用
####1、导入【SQSelectAddress】文件包
####2、调用【SQSelectAddressViewController.h】类
####3、协议声明
@interface ViewController ()<SQSelectAddressViewControllerDelegate>
####4、方法实现
pragma mark -
#pragma mark - SQSelectAddress
///页面添加
-(void)sqSelectAddressPockerView{
SQSelectAddressViewController *selectAddressVC = [[SQSelectAddressViewController alloc] init];
//签署协议
selectAddressVC.delegate = self;
selectAddressVC.animating = NO;
selectAddressVC.footerBg_color = [UIColor greenColor];
selectAddressVC.headerBg_color = [UIColor greenColor];
selectAddressVC.title_font = [UIFont systemFontOfSize:25];
selectAddressVC.titleText_color = [UIColor orangeColor];
[self presentViewController:selectAddressVC animated:YES completion:nil];
}
####5、代理协议实现
- (void)selectAddressViewController:(SQSelectAddressViewController *)selectController selectedDetailAdreess:(NSString *)address townCode:(NSString *)townCode{
NSLog(@"??SQSelectAddress:\n地址=%@ 编码=%@",address,townCode);
}
##四、RattanCityPicker使用
####1、导入[RattanCityPicker]文件包
####2、方法实现
#import "RattanCityPicker.h"
#pragma mark -
#pragma mark - RattanCityPicker
-(void)rattanCity{
RattanCityPicker *picker=[[RattanCityPicker alloc] init];
picker.animation_dur = 0.3;
picker.toolViewBg_color =[UIColor greenColor];
picker.componentFir_font = [UIFont systemFontOfSize:16];
picker.componentStrFir_color = [UIColor redColor];;
picker.componentBgFir_color = [UIColor lightGrayColor];
picker.selectLblStr_font = [UIFont systemFontOfSize:20];
picker.selectLblStr_color = [UIColor redColor];
//点击确定按钮代码块调用
picker.sureBtnBlock = ^(){
};
//获取选择的城市的信息
[picker cityPikerGetSelectCity:^(NSMutableDictionary *dicSelectCity) {
[self setTextLbl:dicSelectCity];
NSLog(@"??RattanCityPicker:\n%@",dicSelectCity);
}];
}
- 源码地址:https://gitee.com/chenzm_186/CityPickerDemo