GitHub
https://github.com/fengli12321/FLNiceSpinner
Example
2017-12-13 23.09.32.gif
這是一個(gè)iOS下拉框控件蓄髓,提供了豐富的屬性自定義UI删窒。同時(shí)實(shí)現(xiàn)了彈出框的自動(dòng)防遮擋枫甲,以及異步數(shù)據(jù)的加載功能(比如網(wǎng)絡(luò)數(shù)據(jù)的請(qǐng)求)
1.同步數(shù)據(jù)
FLNiceSpinner *spinner = [[FLNiceSpinner alloc] initWithFrame:CGRectMake(50, 100, 100, 30)];
spinner.delegate = self;
[self.view addSubview:spinner];
實(shí)現(xiàn)協(xié)議方法
- (NSString *)fl_spinner:(FLNiceSpinner *)spinner showItemStringAtIndex:(NSInteger)index {
if ([spinner isEqual:_spinner1]) {
return _arr1[index];
}
else if ([spinner isEqual:_spinner2]) {
return _arr2[index];
}
else if ([spinner isEqual:_spinner3]) {
return _arr3[index];
}
else if ([spinner isEqual:_spinner4]) {
return _arr4[index];
}
else if ([spinner isEqual:_spinner5]) {
return _arr5[index];
}
else if ([spinner isEqual:_spinner6]) {
return _arr6[index];
}
else if ([spinner isEqual:_spinner7]) {
return _arr7[index];
}
else if ([spinner isEqual:_spinner8]) {
return _arr8[index];
}
else if ([spinner isEqual:_spinner9]) {
return _arr9[index];
}
return nil;
}
- (NSInteger)fl_itemsCountOfSpinner:(FLNiceSpinner *)spinner {
if ([spinner isEqual:_spinner1]) {
return _arr1.count;
}
else if ([spinner isEqual:_spinner2]) {
return _arr2.count;
}
else if ([spinner isEqual:_spinner3]) {
return _arr3.count;
}
else if ([spinner isEqual:_spinner4]) {
return _arr4.count;
}
else if ([spinner isEqual:_spinner5]) {
return _arr5.count;
}
else if ([spinner isEqual:_spinner6]) {
return _arr6.count;
}
else if ([spinner isEqual:_spinner7]) {
return _arr7.count;
}
else if ([spinner isEqual:_spinner8]) {
return _arr8.count;
}
else if ([spinner isEqual:_spinner9]) {
return _arr9.count;
}
return 0;
}
2.異步方法
用于異步數(shù)據(jù)加載,例如數(shù)據(jù)需要通過網(wǎng)絡(luò)加載
FLNiceSpinner *spinner = [[FLNiceSpinner alloc] initWithFrame:CGRectMake(50, 100, 100, 30)];
spinner.delegate = self;
spinner.isAsyncGetData = YES
[self.view addSubview:spinner];
實(shí)現(xiàn)代理方法
- (void)fl_spinner:(FLNiceSpinner *)spinner requestDataSuccess:(void (^)(NSArray<NSString *> *))success fail:(void (^)(void))fail {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
success(@[@"中文", @"英文", @"法語", @"德語", @"西班牙語", @"四川話"]);
});
}
屬性 | 名稱 | 值 |
---|---|---|
占位提示文字 | spaceString | NSString |
文本框文字顏色 | textColor | UIColor |
文本框背景顏色 | backColor | UIColor |
文本框選中后背景顏色 | selectedBackColor | UIColor |
文本框字體大小 | font | UIFont |
清空項(xiàng)提示字符 | clearNoteString | NSString |
列表項(xiàng)文字大小 | listItemFont | UIFont |
列表項(xiàng)高度 | listItemHeight | CGFlot |
列表文字顏色 | listItemTextColor | UIColor |
彈出時(shí)最大顯示行數(shù) | maxShowLines | NSUInteger |
彈出框的背景顏色 | spinnerBackColor | UIColor |
按鈕圓角 | cornerRadius | CGFloat |
展開收起提示用圖標(biāo) | noteImage | NSString |
選中項(xiàng)的下標(biāo) | selectedIndex | NSInteager |
是否是異步的方式獲取數(shù)據(jù) | isAsyncGetData | BOOL |
Requirements
iOS8.0+
Installation
FLNiceSpinner is available through CocoaPods. To install
it, simply add the following line to your Podfile:
可以通過Cocoapods進(jìn)行項(xiàng)目的安裝副瀑,添加如下到你的Podfile文件中:
pod 'FLNiceSpinner'
執(zhí)行
pod install
Author
FoxPower, 954751186@qq.com 歡迎提出問題,歡迎點(diǎn)贊交流
License
FLNiceSpinner is available under the MIT license. See the LICENSE file for more info.