城市選擇器還是比較常見的,由于最近項(xiàng)目中又出現(xiàn)了,所以好好整理了一下,寫了個(gè)輪子,不太完善,使用中有任何issue,請(qǐng)告訴我哦...
對(duì)了,喜歡的請(qǐng)給個(gè)Star...??????
效果圖

CocoaPods:
pod 'SYCitySelectionController', '~> 0.0.4'
Usage:
導(dǎo)入頭文件
#import "SYCitySelectionController.h"
SYCitySelectionController *city = [SYCitySelectionController new];
選擇城市后回調(diào)
city.selectCity = ^(NSString *city) {
NSLog(@"%@", city);
[self.locateBarButton setTitle:city];
};
當(dāng)前位置
city.currentCityName = @"廈門市";
開啟定位(上面設(shè)置無效,請(qǐng)真機(jī)調(diào)試)
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];