类似淘宝的选择价格区间Demo
来源:互联网 发布:linux指令速查手册 编辑:程序博客网 时间:2024/04/30 11:35
1、大致搭建UI:
2、键盘
(1)点击空白处退下键盘
@property (weak, nonatomic) IBOutlet UITextField *lowPrice;@property (weak, nonatomic) IBOutlet UITextField *highPrice;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [_lowPrice resignFirstResponder]; [_highPrice resignFirstResponder];}
(2)右上角添加”确定”按钮
这里关键就是给textField添加inputAccessoryView
// 创建“完成”按钮 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 90, 7, 80, 30)]; button.layer.cornerRadius = 5; button.layer.borderWidth = 0.5; button.layer.borderColor = [UIColor grayColor].CGColor; [button setTitle:@"完成"forState:UIControlStateNormal]; button.titleLabel.font = [UIFont systemFontOfSize:14]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(refreshPriceInterval) forControlEvents:UIControlEventTouchUpInside];
- (void)refreshPriceInterval { time = 2; // 这个地方模拟拉取网络数据(更新成对应价格区间的商品)所需的时间 [_lowPrice resignFirstResponder]; [_highPrice resignFirstResponder]; // 数据大小判断 if((![_lowPrice.text isEqualToString:@""]) && (![_highPrice.text isEqualToString:@""])) { if([_lowPrice.text integerValue] > [_highPrice.text integerValue]) { _lowP = _highPrice.text; _highP = _lowPrice.text; } } else { _lowP = _lowPrice.text; _highP = _highPrice.text; } [_activityIndicatorView startAnimating]; [self hideActivityIndicatorView];}- (void)hideActivityIndicatorView { _myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:_myTimer forMode:NSRunLoopCommonModes];}- (void)updateTimer { time--; // 判断是否拉取完数据 if (time == 0) { _lowPrice.text = _lowP ; _highPrice.text = _highP; [self.myTimer invalidate]; [self.activityIndicatorView stopAnimating]; }}
// 给textField添加inputAccessoryView
【方法一】:用UIView
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)]; [view setBackgroundColor: [UIColor colorWithRed:210/250.0 green:214/250.0 blue:220/250.0 alpha:1.0]]; [view addSubview:button]; _lowPrice.inputAccessoryView = view; _highPrice.inputAccessoryView = view;
【方法二】:用UIToolBar
用barTintColor设置UIToolBar的背景色
UIToolbar *view = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)]; view.barTintColor = [UIColor colorWithRed:210/250.0 green:214/250.0 blue:220/250.0 alpha:1.0]; // 注意:是barTintColor[view addSubview:button];_lowPrice.inputAccessoryView = view;_highPrice.inputAccessoryView = view;
到此,可以运行看到效果:
3、添加转动的小菊花
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView;
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];_activityIndicatorView.color = [UIColor grayColor];_activityIndicatorView.frame = self.view.bounds;[self.view addSubview:_activityIndicatorView];
完整的Demo可以在:https://github.com/Yangchengfeng/IntervalOfPrice查看
这里所说的“类似淘宝的选择价格区间”并没有置于tableView和scrollView之上来做的,所以未涉及到上面所讲视图引起的问题,待后续···
1 0
- 类似淘宝的选择价格区间Demo
- 实现滑动选择价格区间的自定义seekbar
- 价格区间选择案例 吸附功能
- ecshop价格范围区间用户自定义选择价格代码
- 今天实现了类似淘宝上划操作显示详情页的demo
- 类似淘宝的星星打分
- 【仿汽车之家】价格区间选择控件
- 类似条件式的选择
- 类似气泡的样式demo
- iOS-导航栏,类似淘宝“我的淘宝”导航栏
- 类似QQ、淘宝旺旺的网页代码
- 类似淘宝搜索排序的例子
- 类似淘宝的滑动评分,很好用!!!
- 类似淘宝的搜索智能提示
- 列出类似淘宝网站的分类菜单
- 类似淘宝订单列表的改进
- 有没有类似淘宝app的例子
- 有没有类似淘宝app的例子
- stm32 定时器
- Android Studio查看程序安全码获取SHA1值
- RTP解包
- iOS 开发中,如何实现高效的大量(如十万级)推送通知?
- 谷歌插件开发(2)-修改百度页面
- 类似淘宝的选择价格区间Demo
- webrtc声音回声消除算法选择
- POJ3046 Ant Counting DP 隔板法讲解 有图有真相
- map集合取数据的几种方法
- Android Studio+Appium+TestNG数据驱动框架搭建
- Windows Server 2008远程桌面端口更改方法
- 适配 iOS 10,极光推送用户要做这 6 处更改
- HBase + Solr Cloud实现HBase二级索引
- [LeetCode]Set Matrix Zeroes