iOS模仿京东商城中的选择地区样式
在ViewController文件中创建添加地址界面:
@property(nonatomic,strong)UILabel *selectAreaLabel;//地区显示
@property(nonatomic,strong)UITextField *nameTextF;//收货人
@property(nonatomic,strong)UITextField *phoneTextF;//联系方式
@property(nonatomic,strong)UITextField *addressTextF;//详细地址
@property(nonatomic,copy)NSString *switchStr;//选择按钮值
@property(nonatomic,strong)SelectAreaView *selectView;//选择地区视图
@property(nonatomic,strong)UIView *smallBgView;//选择地区下方白色区域
@property(nonatomic,strong)NSMutableArray *dataArray1;//地址列表数据
@property(nonatomic,strong)NSMutableArray *areaInfoArray;//返回地址相关信息
在数据请求成功后,添加半透明背景,添加可选择的地区列表:
if (success)
{
NSArray *itemArray = [[resultDic[@"ITEMS"] reverseObjectEnumerator] allObjects];
for (NSDictionary *dic in itemArray)
{
[_dataArray1 addObject:dic];
}
_smallBgView = [[UIView alloc] initWithFrame:CGRectMake(0, f_Device_h, f_Device_w, f_Device_h)];
_smallBgView.backgroundColor = [UIColor darkGrayColor];
_smallBgView.alpha = 0.8;
[self.view addSubview:_smallBgView];
_selectView = [[SelectAreaView alloc] initWithProvinceList:CGRectMake(0, f_Device_h, f_Device_w, f_Device_h/3*2) dataArray:_dataArray1];
[self.view addSubview:_selectView];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(downSmallBgView:) name:@"downSmallBgV" object:nil];
}
添加一个通知实现当地区选择完成落下来后,执行的方法
#pragma mark --- 接收到通知
-(void)downSmallBgView:(NSNotification *)notifi
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
_smallBgView.frame = CGRectMake(0, f_Device_h, f_Device_w, f_Device_h);
_selectView.frame = CGRectMake(0, f_Device_h, f_Device_w, f_Device_h/3*2);
[UIView commitAnimations];
NSDictionary *dic = [notifi userInfo];
_areaInfoArray = [NSMutableArray arrayWithArray:dic[@"areaArray"]];
if (_areaInfoArray.count > 0)
{
NSMutableString *muStr = [NSMutableString new];
for (NSDictionary *areaDic in _areaInfoArray)
{
NSString *nameStr = areaDic[@"adName"];
if (nameStr.length >0)
{
[muStr appendString:nameStr];
}
}
_selectAreaLabel.text = muStr;
}
else
{
_selectAreaLabel.text = @"无";
}
}
自定义一个选择视图
//初始化视图方法
-(id)initWithProvinceList:(CGRect)frame dataArray:(NSMutableArray *)aDataArray
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor whiteColor];
self.itemDic = @{@"adCode":@"",@"adName":@"",@"id":@"",@"parentId":@""};
self.areaMuArray = [NSMutableArray arrayWithObjects:_itemDic,_itemDic,_itemDic, nil];
self.dataArray1 = [NSMutableArray arrayWithArray: aDataArray];
self.dataArray2 = [NSMutableArray new];
self.dataArray3 = [NSMutableArray new];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, f_Device_w, 40)];
titleLabel.text = @"选择地区";
titleLabel.textColor = [UIColor darkGrayColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont systemFontOfSize:15];
[self addSubview:titleLabel];
UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
closeBtn.frame = CGRectMake(f_Device_w-40, 5, 30, 30);
[closeBtn setBackgroundImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
[self addSubview:closeBtn];
[closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//省市区按钮
for (int i = 0; i < 3; i ++)
{
UIButton *sBtn = [UIButton buttonWithType:UIButtonTypeCustom];
sBtn.frame = CGRectMake(20+50*i, 45, 50, 29);
if (i == 0)
{
[sBtn setTitle:@"请选择" forState:UIControlStateNormal];
}
sBtn.titleLabel.font = [UIFont systemFontOfSize:13];
sBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
[sBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
sBtn.tag = i+10;
[sBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:sBtn];
}
//分割
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 74, f_Device_w, 1)];
lineView.backgroundColor = [UIColor lightGrayColor];
[self addSubview:lineView];
_scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 75, f_Device_w, f_Device_h-f_Device_h/3-75)];
_scrollV.showsHorizontalScrollIndicator = NO;
_scrollV.pagingEnabled = YES;
[self addSubview:_scrollV];
for (int i = 0; i < 3; i ++)
{
UITableView *tableViewW = [[UITableView alloc] initWithFrame:CGRectMake(f_Device_w*i, 0, f_Device_w, f_Device_h-f_Device_h/3-75) style:UITableViewStylePlain];
tableViewW.delegate = self;
tableViewW.dataSource = self;
tableViewW.rowHeight = 30;
tableViewW.tag = i+1;
tableViewW.separatorStyle = UITableViewCellSeparatorStyleNone;
[_scrollV addSubview:tableViewW];
}
}
return self;
}
当选择地区后,执行的方法
#pragma mark --- 选中后执行方法
//参数说明:1:上一个表格数组,2:点击的是第几行数据,3:标题按钮的tag值,4:滑动视图有几个f_Device_w,5:下一个表格数组
-(void)showSelectViewArray1:(NSMutableArray *)aDataArray1 indexPathRow:(int)aRow buttonTag1:(int)aTag1 xPoint:(int)aXi dataArray2:(NSMutableArray *)aDataArray2
{
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:aDataArray1[aRow]];
UIButton *buttonN1 = (UIButton *)[self viewWithTag:aTag1];
[buttonN1 setTitle:dic[@"adName"] forState:UIControlStateNormal];
[buttonN1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_areaMuArray replaceObjectAtIndex:aXi-2 withObject:dic];
[self cityListHttpRequestIdStr:dic[@"id"] dataArray2:aDataArray2 buttonTag:aTag1 tableViewTag:aXi];
}
#pragma mark --- 市县区数据请求
//参数说明:1:上一个表格数组中的id,2:下一个表格数组,3:标题按钮tag值,4:tableView的tag值
-(void)cityListHttpRequestIdStr:(NSString *)parentIdStr dataArray2:(NSMutableArray *)aDataArray2 buttonTag:(int)btnTag tableViewTag:(int)aTag
效果图:
仿京东商城选择地区样式详细讲解源码Demo:http://download.csdn.net/detail/hbblzjy/9603813
iOS模仿京东商城中的选择地区样式的更多相关文章
- 商城项目实战 | 2.1 Android 仿京东商城——自定义 Toolbar (一)
前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 现在很多的 APP 里面都有自己的自定义风格,特别是京东商城中自 ...
- 商城项目实战 | 1.1 Android 仿京东商城底部布局的选择效果 —— Selector 选择器的实现
前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 京东商城的底部布局的选择效果看上去很复杂,其实很简单,这主要是要 ...
- [js开源组件开发]js手机联动选择地区仿ios 开源git
js手机联动选择地区 前言:由于网上找到了一个mobiscrool,比较全,但是不开源,只能试用15天,正式版竟然要三千块钱,穷人只能自己动手,写了个只针对弹窗地区选择的. 本站点所有的资源均在git ...
- iOS仿京东分类菜单之UICollectionView内容
在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...
- ThinkPHP3.2开发仿京东商城项目实战视频教程
ThinkPHP3.2仿京东商城视频教程实战课程,ThinkPHP3.2开发大型商城项目实战视频 第一天 1.项目说明 2.时间插件.XSS过滤.在线编辑器使用 3.商品的删除 4.商品的修改完成-一 ...
- Python网络爬虫——京东商城商品列表
Python_网络爬虫--京东商城商品列表 最近在拓展自己知识面,想学习一下其他的编程语言,处于多方的考虑最终选择了Python,Python从发布之初就以庞大的用户集群占据了编程的一席之地,pyth ...
- Android 深入ViewPager补间动画,实现类京东商城首页广告Banner切换效果
如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 某天看到京东商城首页的滑动广告的Banner,在流动切换的时候有立体的动画效果,感觉很有意思,然后研究了下 ...
- iOS已发布应用中对异常信息捕获和处理
iOS已发布应用中对异常信息捕获和处理 iOS开发中我们会遇到程序抛出异常退出的情况,如果是在调试的过程中,异常的信息是一目了然,但是如果是在已经发布的程序中,获取异常的信息有时候是比较困难的. iO ...
- 商城项目实战 | 2.2 Android 仿京东商城——自定义 Toolbar (二)
本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 上一篇文章<商城项目实战 | 2.1 Android 仿京东商城 ...
随机推荐
- Linux中Mysql root用户看不到mysql库问题解决方式
第一种方式: 1.首先停止MySQL服务:service mysqld stop2.加参数启动mysql:/usr/bin/mysqld_safe --skip-grant-tables & ...
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
IE8报错误: 用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .N ...
- 在循环列表的富文本里摘出每个item的img标签内容(适合vue渲染)
昨天在做公司项目的社区动态内容.后台接口返回的数据是数组套对象,对象里有富文本,然后需要摘出富文本里的img标签在列表里分开渲染(即图片九宫格样式).最终效果如图: 这个是后盾接口返回的json数据 ...
- Java面试19|过于深入的问题
1.synchronized关键字的实现原理 可以参考:http://www.jianshu.com/p/c5058b6fe8e5 2.CAS是由Unsafe类的compareAndSwap()方法实 ...
- 利用JAVA多线程来提高数据处理效率
肿瘤大数据挖掘中经常需要处理上百亿行的文本文件,这些文件往往高达数百GB,假如文件结构简单统一,那么用sed和awk 处理是非常方便和快速的.但有时候会遇到逻辑较为复杂的处理流程,这样我一般会用JAV ...
- Node.js HTTPS
稳定性: 3 - 稳定 HTTPS 是基于 TLS/SSL 的 HTTP 协议.在 Node 里作为单独的模块来实现. 类: https.Server 这是 tls.Server 的子类,并且和 ht ...
- Docker服务端防护
运行一个容器或应用程序的核心是通过 Docker 服务端.Docker 服务的运行目前需要 root 权限,因此其安全性十分关键. 首先,确保只有可信的用户才可以访问 Docker 服务.Docker ...
- Java语言程序设计-Markdown格式作业模板
Markdown格式作业模板如下,大家可以直接复制粘贴使用. 注意:作业中不能只写答案,题目本身也要出现.. # 1. 本章学习总结 你对于本章知识的学习总结 # 2. 书面作业 **Q1 java ...
- 周口网视界易付点卡销售平台招商中 www.zkpay.cn 欢迎各界朋友加盟合作。
周口网视界易付点卡销售平台针对全国各地网吧及游戏点卡代理招商中. http://www.zkpay.cn 腾讯新的游戏点卡销售平台,平台价优稳定,这个是老家朋友开的公司,欢迎全国各地网吧客户及游戏 ...
- Hadoop2动态调整Log级别-以datanode的heartbeat log为例
在Hadoop中,有些log信息在正常情况下是不打印出来的.比如datanode发送heartbeat的日志. 代码位于BPServiceActor#sendHeartBeat方法中,如下图: 由于默 ...