注:本文所有图片保存EverNote 印象笔记(www.yinxiang.com)当中, 如果有其帐号登录后即可查看全部图片。 如没有帐号可用e-mail >>点击注册免费印象笔记
iOS 下单选列表实现方案
在iOS 常见的设置窗口,经常有单选列表的界面。
有多种实现方案,最常见的就是象系统设置一样,再新开一个列表窗口后选择完,回退到上一个窗口。
这种方案最大问题,在storyboard下模式,如果有多个选择列表,就要绘制多个窗口,工程量很大。
一.levey 单选列表类
在网上搜索到开源项目 leveyPopListView
https://github.com/levey/LeveyPopListView
发现只需要引入类后,几句代码即可实现单选列表,相当方便
二.popListView 使用
引入很简单
- 引入levey代码
- 定义NSArray 定义列表
- 显示及响应处理
定义NSArray列表
_options = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"facebook.png"],@"img",@"Facebook",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"twitter.png"],@"img",@"Twitter",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"tumblr.png"],@"img",@"Tumblr",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"google-plus.png"],@"img",@"Google+",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"linkedin.png"],@"img",@"LinkedIn",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"pinterest.png"],@"img",@"Pinterest",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"dribbble.png"],@"img",@"Dribbble",@"text", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"deviant-art.png"],@"img",@"deviantArt",@"text", nil],
nil];
显示
- (void)showListView {
LeveyPopListView *lplv = [[LeveyPopListView alloc] initWithTitle:@"Share Photo to..." options:_options handler:^(NSInteger anIndex) {
//这里根据anIndex值写上响应代码
}];
// lplv.delegate = self;
[lplv showInView:self.window animated:YES];
}
最后附上项目中效果图