IOS控制項 UIDatePicker

來源:互聯網
上載者:User

標籤:des   style   class   blog   code   http   

效果

 

初始化
UIDatePicker *pick = [[UIDatePicker alloc] init];
屬性1. 模式
pick.datePickerMode = UIDatePickerModeTime;

可寫屬性有

    UIDatePickerModeTime,           // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)    UIDatePickerModeDate,           // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)    UIDatePickerModeDateAndTime,    // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)    UIDatePickerModeCountDownTimer, // Displays hour and minute (e.g. 1 | 53)
監聽1. 添加監聽
[pick addTarget:self action:@selector(setTimeOK:) forControlEvents:UIControlEventValueChanged];
2. 實現監聽
- (void)setTimeOK:(UIDatePicker *)sender{    NSDate *date = sender.date;    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; 
NSString *dateStr = [formatter stringFromDate:date];
self.textField.text = [NSString stringWithFormat:@"%@", dateStr];
}
typedef enum {    NSDateFormatterNoStyle     = kCFDateFormatterNoStyle,    NSDateFormatterShortStyle  = kCFDateFormatterShortStyle,//“11/23/37” or “3:30pm”    NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,//\"Nov 23, 1937\"    NSDateFormatterLongStyle   = kCFDateFormatterLongStyle,//\"November 23, 1937” or “3:30:32pm\"    NSDateFormatterFullStyle   = kCFDateFormatterFullStyle//“Tuesday, April 12, 1952 AD” or “3:30:42pm PST”} NSDateFormatterStyle;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.