iOS出生日期时间选择器、倒计时,籍贯选择器
来源:互联网 发布:注册城市规划师 知乎 编辑:程序博客网 时间:2024/05/01 23:53
出生日期时间选择器、倒计时。datePickerMode自己去改就可以了,很简单,上代码了
我还自己写了一个籍贯的选择器,plist文件,自己去找
或者去github上,下载我的demo
附上链接
demo链接
// ViewController.m// UIDatePicker//// Created by 易云时代 on 2017/8/21.// Copyright © 2017年 笑伟. All rights reserved.//#import "ViewController.h"#import <Foundation/NSObject.h>@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>@property (nonatomic, strong) UIDatePicker *picker;//日期选择器@property (nonatomic, strong) UILabel *label;//显示日期@property (nonatomic, strong) UIPickerView *pickerView;@property (nonatomic, strong) NSDictionary *dataSource;//数据源@property (nonatomic, strong) NSArray *provArr;//省@property (nonatomic, strong) NSArray *cityArr;//市@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; /*日期选择器*/ _picker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 300, 160)];//选择器初始化 _picker.locale = [NSLocale localeWithLocaleIdentifier:@"zh-hans"];//简体中文 _picker.datePickerMode = UIDatePickerModeDate;//日期的模式 [self.view addSubview:_picker]; _label = [[UILabel alloc]initWithFrame:CGRectMake(0, 180, 300, 30)]; _label.layer.borderWidth = 1; _label.text = @"时间"; _label.textAlignment = NSTextAlignmentCenter; [self.view addSubview:_label]; UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 220, 100, 30)]; [button setTitle:@"Click" forState:UIControlStateNormal]; button.backgroundColor = [UIColor redColor]; [button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; /*籍贯选择器*/ _pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 260, 300, 160)]; _pickerView.delegate = self; _pickerView.dataSource = self; [self.view addSubview:_pickerView]; //获取数据 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"ProvinceList" ofType:@"plist"]; NSDictionary *dic = [[NSDictionary alloc]initWithContentsOfFile:plistPath]; _dataSource = dic; _provArr = [_dataSource allKeys]; //默认第一个 NSString *seledPrvo = [_provArr objectAtIndex:0]; _cityArr = [_dataSource objectForKey:seledPrvo];}-(void)onClick:(id)sender{ NSDate *date = _picker.date; NSDateFormatter *matter = [[NSDateFormatter alloc]init]; matter.dateFormat = @"YYYY-MM-dd HH:mm:ss"; _label.text = [matter stringFromDate:date];}#pragma mark UIpickerViewDataSource-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2;}-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ if(component == 0){//省 return _provArr.count; }else{//市 return _cityArr.count; }}#pragma mark UIpickerViewDelegate-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ if (component == 0) {//省份 return [_provArr objectAtIndex:row]; }else{//城市 return [_cityArr objectAtIndex:row]; }}-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ if (component == 0) { NSString *selectedProv = [_provArr objectAtIndex:row]; NSArray *arr = [_dataSource objectForKey:selectedProv]; _cityArr = arr; [_pickerView reloadComponent:1]; }}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- iOS出生日期时间选择器、倒计时,籍贯选择器
- iOS 时间选择器
- iOS时间选择器
- iOS 开发时间选择器datePicker
- iOS - UITextFieldKeyBoardPan为时间选择器
- iOS 时间/ 日期选择器 UIDatePicker
- 仿ios的时间选择器
- 普通选择器的使用--选择籍贯
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 程序是如何执行的(三)函数调用
- PAT_1076. Forwards on Weibo
- Android Socket网络通信
- ionic中typescript javascript调用高德地图
- 2017.8.17每天五个编程题(十)
- iOS出生日期时间选择器、倒计时,籍贯选择器
- 堆排序算法
- python简单实现天猫手机评论标签提取--自然语言处理
- hdu 2049 不容易系列之(4)——考新郎(错排)
- C# winform 开发总结 -- 【持续更新】
- String、Stringbuilder和Stringbuffer
- windows下使用composer安装thinkPHP5
- JEESZ分布式框架--技术介绍文档
- cmake和make区别(转载)