iOS datepicker 怎么用代码设置只显示年月日
1个回答
2016-03-15 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
可以选择自己需要的模式,Time, Date,Date and Time , Count Down Timer四种模式。
具体的步骤如下:
1.新建一个Singe View Application工程 ,拖动一个DatePicker控件 和 Button到界面。
2.然后关联Button事件(可以按住Ctrl拖动实现)
3.实现代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
*/
//datePicker.datePickerMode = UIDatePickerModeDateAndTime;//这儿即是改变显示的模式
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)datePick:(id)sender {
NSDate *select = [datePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yy-MM-dd HH:mm:ss"];
NSString *dateAndTime = [dateFormatter stringFromDate:select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 时间提示" message: dateAndTime delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
具体的步骤如下:
1.新建一个Singe View Application工程 ,拖动一个DatePicker控件 和 Button到界面。
2.然后关联Button事件(可以按住Ctrl拖动实现)
3.实现代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
*/
//datePicker.datePickerMode = UIDatePickerModeDateAndTime;//这儿即是改变显示的模式
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)datePick:(id)sender {
NSDate *select = [datePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yy-MM-dd HH:mm:ss"];
NSString *dateAndTime = [dateFormatter stringFromDate:select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 时间提示" message: dateAndTime delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询