iOS開發UI篇—Date Picker和UITool Bar控制項簡單介紹

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   sp   

iOS開發UI—Date PickerUITool Bar控制項簡單介紹

一、Date Picker控制項

1.簡單介紹:

 

Date Picker顯示時間的控制項

有預設寬高,不用設定資料來源和代理

如何改成中文的?

(1)查看當前系統是否為中文的,把模擬器改成是中文的

(2)屬性,locale選擇地區

如果預設顯示不符合需求。時間有四種模式可以設定,在model中進行設定

時間可以自訂(custom)。

設定最小時間和最大時間,超過就會自動回到最小時間。

最大的用途在於自訂鍵盤:彈出一個日期選取器出來,範例程式碼如下:

 

 2.範例程式碼

 

  1 #import "TXViewController.h"  2   3    4   5 @interface TXViewController ()  6   7 /**  8   9  *  文本輸入框 10  11  */ 12  13 @property (weak, nonatomic) IBOutlet UITextField *textfired; 14  15   16  17 @end 18  19   20  21 @implementation TXViewController 22  23   24  25 - (void)viewDidLoad 26  27 { 28  29     [super viewDidLoad]; 30  31 //添加一個時間選取器 32  33     UIDatePicker *data = [[UIDatePicker alloc]init]; 34  35      36  37     //設定只顯示中文 38  39      40  41     [data setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]]; 42  43     //只顯示日期 44  45     data.datePickerMode = UIDatePickerModeDate; 46  47      48  49      50  51     //當游標移動到文字框時,召喚時間選取器 52  53      54  55     self.textfired.inputView = data; 56  57      58  59     //2建立工具條 60  61     UIToolbar *toolbar = [[UIToolbar alloc]init]; 62  63      64  65     //設定工具條的顏色 66  67      68  69     toolbar.barTintColor = [UIColor redColor]; 70  71      72  73     //設定工具條的顏色 74  75     toolbar.frame = CGRectMake(0, 0, 320, 55); 76  77      78  79     //給工具條添加按鈕 80  81      82  83     UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一個"style:UIBarButtonItemStylePlaintarget:self action:@selector(didClick) ]; 84  85     UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一個"style:UIBarButtonItemStylePlaintarget:self action:@selector(didClick) ]; 86  87     //彈簧 88  89     UIBarButtonItem *item2=[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nil action:nil]; 90  91     UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成"style:UIBarButtonItemStylePlain target:self action:@selector(didClick)]; 92  93     toolbar.items = @[item0,item1,item2,item3]; 94  95      96  97     //設定文本輸入框鍵盤的輔助視圖 98  99          self.textfired.inputAccessoryView=toolbar;100 101 }102 103 -(void)didClick104 105 {106 107     NSLog(@"fjlsd");108 109     110 111 }112 113 - (void)didReceiveMemoryWarning114 115 {116 117     [super didReceiveMemoryWarning];118 119     // Dispose of any resources that can berecreated.120 121 }122 123  124 125 @end

 

實現效果:

二、UITool Bar

在上面可以添加子控制項TOOLBAR中只能添加UIBarButtonItem子控制項,其他子控制項會被封裝秤這種類型的

上面的控制項依次排放(空格————)

有樣式,可以指定樣式(可展開的),一般用來做工具列。

 

使用toolbar做點菜的頭部標題

如何讓點菜系統置中?在ios6中是正的,在ios7中是歪的

在自訂鍵盤上加上一個工具列。

數組裡什麼順序放的,就按照什麼順序顯示

  toolbar.items = @[item0,item1, item2, item3];
    //設定文本輸入框鍵盤的輔助視圖
   self.textfield.inputAccessoryView=toolbar;

iOS開發UI篇—Date Picker和UITool Bar控制項簡單介紹

聯繫我們

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