iOS UI基礎-14.0 DatePicker

來源:互聯網
上載者:User

標籤:

DatePicker的主要屬性:

  • Mode:顯示的內容,可以選擇日期、時間的自由組合
  • Locale:顯示的語言樣式
  • Interval:每個選項的時間間隔
  • Date:當前選擇的時間
  • Constraint:指定最小和最大時間
  • Timer:計時器

使用代碼建立DatePicker

// 1.建立DatePicker    UIDatePicker *datePicker = [[UIDatePicker alloc] init];    // 2.設定模式    [datePicker setDatePickerMode:UIDatePickerModeDate];    // 3.設定locale    [datePicker setLocale:[NSLocale localeWithLocaleIdentifier:@"zh_CN"]];    // 4.設定textField的響應鍵盤為DatePicker    [self.textField setInputView:datePicker];

使用代碼建立UIToolBar

// 1.建立UIToolBar    UIToolbar *toolBar = [[UIToolbar alloc] init];    toolBar.barTintColor = [UIColor grayColor]; // 這個才是UIToolBar的背景色    toolBar.frame = CGRectMake(0, 0, 320, 44); // 必須設定好size,UIToolBar才能顯示,否則只能顯示Item,且不能點擊    // 2.建立Item    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一個" style:UIBarButtonItemStylePlain target:self action:@selector(previousClicked)];       UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一個" style:UIBarButtonItemStylePlain target:self action:@selector(nextClicked)];       UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(finishClicked)];       // 間隙Item    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];       // 3.添加Item到UIToolBar    toolBar.items = @[item1, item2, spaceItem, item3];       // 4.添加UIToolBar到鍵盤上方,設定為textField的輔助視圖    self.textField.inputAccessoryView = toolBar;

 

iOS UI基礎-14.0 DatePicker

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.