城市选择器还是比较常见的,由于最近项目中又出现了,所以好好整理了一下,写了个轮子,不太完善,使用中有任何issue,请告诉我哦...
对了,喜欢的请给个Star...🙏🙏🙏
效果图
CocoaPods:
pod 'SYCitySelectionController', '~> 0.0.4'
Usage:
导入头文件
#import "SYCitySelectionController.h"
SYCitySelectionController *city = [SYCitySelectionController new];
选择城市后回调
city.selectCity = ^(NSString *city) {
NSLog(@"%@", city);
[self.locateBarButton setTitle:city];
};
当前位置
city.currentCityName = @"厦门市";
开启定位(上面设置无效,请真机调试)
city.openLocation = YES;
返回按钮
city.currentCityName = @"厦门市";
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setTitle:@"Click Me Back" forState:UIControlStateNormal];
[b sizeToFit];
b.backgroundColor = [UIColor cyanColor];
city.backView = b;
热门城市
city.hotCitys = @[@"上海市", @"天津市", @"北京市", @"杭州市", @"厦门市", @"广州市", @"深圳市"];
所有城市
city.citys = @[@"上海市", @"天津市", @"北京市", @"杭州市", @"厦门市", @"广州市", @"深圳市"];
自己的城市Dict
NSArray *citys = @[@[@"上海市", @"深圳市"], @[@"天津市"], @[@"北京市"], @[@"杭州市"], @[@"厦门市"], @[@"广州市"]];
NSArray *index = @[@"S", @"T", @"B", @"H", @"X", @"G"];
city.cityDict = [NSDictionary dictionaryWithObjects:citys forKeys:index];