iPhone:DatePicker dd / mm / yyyy [英] iPhone:DatePicker dd/mm/yyyy

查看:233
本文介绍了iPhone:DatePicker dd / mm / yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击textField时,我正在使用带有弹出窗口的DatePicker。但是,Picker显示月份首先,而不是首先显示日期,并不是英国的写日期的方式。
有没有办法将DatePicker的日期格式设置为英制的方式,如dd / mm / yyyy?
我正在使用Achtionsheet:

I am using a DatePicker with popups when a user click a textField. However, the Picker displays Month first, not date first and it isn't British way to write a date. Is there any way to set the date format in DatePicker to British way such as dd/mm/yyyy? I am using an Achtionsheet:

-(IBAction)acsheet:(id)sender
{

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                              delegate:nil
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:nil];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    //CGRect pickerFrame = CGRectMake(0, 45, 0, 0);
    pickerView1 = [[UIDatePicker alloc] init];
    pickerView1.datePickerMode = UIDatePickerModeDate;  

    [actionSheet addSubview:pickerView1];

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet:)                    
                      forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];
    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];    
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

    [pickerView1 addTarget:self
                    action:@selector(updateLabel:)
          forControlEvents:UIControlEventValueChanged]; 

    UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self  action:@selector(dismissDatePicker:)] ;
    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
    toolBar.tag = 11;
    toolBar.barStyle = UIBarStyleBlackTranslucent;

    [toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
    [self.view addSubview:toolBar];

}


推荐答案

code> UIDatePicker ,默认情况下,使用任何 [NSLocale currentLocale] 命令。

The UIDatePicker, by default, uses whatever [NSLocale currentLocale] dictates.

在iOS 5中已经不推荐使用 UIDatePicker 上的 locale 属性,但我相信您可以执行以下操作:

The locale property on UIDatePicker was deprecated in iOS 5, but I believe that you could do the following:

NSCalendar *cal = [NSCalendar currentCalendar];
cal.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
myDatePicker.calendar = cal;

这个应该工作。如果没有,请提交错误,我会解决它。 :)

This should work. If it doesn't, please file a bug and I'll fix it. :)

这篇关于iPhone:DatePicker dd / mm / yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆