DropdownListView下拉列表,选项列表支持自定义
查看次数:12225
下载次数:1569
上传时间:2015-07-27
大小:976 B
DropdownListView创建方式如下:
- (void)setupDropdownList
{
ddltView = [[XIOptionSelectorView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 40)];
ddltView.parentView = self.view;
ddltView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:ddltView];
__weak typeof(self) weakSelf = self;
[ddltView setViewAtIndex:^UIView *(NSInteger index, XIOptionSelectorView*opView) {
XIOptionSelectorView *strongOpSelectorRef = opView;
UIView *aView;
CGFloat py = strongOpSelectorRef.frame.size.height+strongOpSelectorRef.frame.origin.y;
CGFloat dpW = weakSelf.view.frame.size.width;
if(index<2){
aView = [[XIOptionView alloc] initWithFrame:CGRectMake(0, py, dpW, 240)];
aView.backgroundColor = [UIColor whiteColor];
aView.delegate = weakSelf;
aView.viewIndex = index;
NSArray *tmpArray = (index==0)? @[@"Tracking", @"Processing", @"Processed"]:@[@"Ascending", @"Descending"];
[aView setFetchDataSource:^NSArray *{
return tmpArray;
}];
}
else{
aView = [[XIOtherOptionsView alloc] initWithFrame:CGRectMake(0, py, dpW, 240)];
aView.backgroundColor = [UIColor whiteColor];
aView.delegate = weakSelf;
aView.viewIndex = index;
[aView setFetchDataSource:^NSArray *{
return @[@"Choose the specified order", @"Clear all selections"];
}];
}
aView.hidden = YES;
[weakSelf.view addSubview:aView];
return aView;
}];
}
将下拉选项列表放在view controller里初始化的目的是方便自行定制样式,XIOptionView、XIOtherOptionsView只是提供2种自定义的方式,自定义View时请conform protocol XIDropdownlistViewProtocol。
测试环境:Xcode 6.2,iOS 6.0 以上
收藏