iOS开发:城市选择器集成

一、简介
该项目集成了三种类型的城市选择器:

1、XXCityPickerView 省市区,可以分级:1省 2省-市 3省-市-区
2、SQSelectAddress 省市区乡/镇,页面跳转
3、RattanCityPicker 省市区,包含邮编地址,开放多个属性设置的接口
二、XXCityPickerView使用
1、从该项目导入【XXCityPickerView】文件包
2、 导入系统库 :libsqlite3.tbd
3、方法实现

1 #import “XXCityPickerView.h”
2
3 @interface ViewController ()<XXCityPickerViewDelegate>
4
5 @property(nonatomic,strong)XXCityPickerView *cityPicker;
6
7 @end
8
9 @implementation ViewController
10
11 – (void)viewDidLoad {
12     [super viewDidLoad];
13 }
14
15 ///方法调用
16 -(void)clickAction{
17     [self cityPicker];
18 }
19
20 – (XXCityPickerView *)cityPicker{
21     if (_cityPicker == nil){
22         // 初始化  设置类别   1省  2省-市  3省-市-区
23         _cityPicker = [[XXCityPickerView alloc]initWithComponents:3];
24         // 设置代理
25         _cityPicker.delegate = self;
26         [self.view addSubview:_cityPicker];
27     }
28     return  _cityPicker;
29 }

4、代理实现

1 // —- 【XXCityPickerViewDelegate】
2 // 取消
3 – (void)XXCityPickerViewLeftAction{
4     [self removeCityPickerView];
5 }
6 // 完成
7 – (void)XXCityPickerViewRightAction:(XXCityPickerView *)picker andCity:(NSString *)city andData:(NSMutableDictionary *)dic{
8     [self removeCityPickerView];
9     NSLog(@”������XXCityPickerView:\n city= %@   dic= %@”,city,dic);
10 }
11
12 -(void)removeCityPickerView{
13     if (_cityPicker) {
14         [_cityPicker removeFromSuperview];
15         _cityPicker = nil;
16     }
17 }

 

三、SQSelectAddress使用
1、导入【SQSelectAddress】文件包
2、调用【SQSelectAddressViewController.h】类
3、协议声明
@interface ViewController ()<SQSelectAddressViewControllerDelegate>
1
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];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
5、代理协议实现
– (void)selectAddressViewController:(SQSelectAddressViewController *)selectController selectedDetailAdreess:(NSString *)address townCode:(NSString *)townCode{
NSLog(@”����SQSelectAddress:\n地址=%@ 编码=%@”,address,townCode);
}
1
2
3
四、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);
}];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2