標籤:style blog http io color ar os 使用 sp
iOS開發UI篇—Date Picker和UITool Bar控制項簡單介紹
一、Date Picker控制項1.簡單介紹:Date Picker顯示時間的控制項有預設寬高,不用設定資料來源和代理如何改成中文的?(1)查看當前系統是否為中文的,把模擬器改成是中文的(2)屬性,locale選擇地區如果預設顯示不符合需求。時間有四種模式可以設定,在model中進行設定時間可以自訂(custom)。設定最小時間和最大時間,超過就會自動回到最小時間。最大的用途在於自訂鍵盤:彈出一個日期選取器出來,範例程式碼如下: 2.範例程式碼
1 // 2 // YYViewController.m 3 // datepicker 4 // 5 // Created by apple on 14-6-3. 6 // Copyright (c) 2014年 itcase. All rights reserved. 7 // 8 9 #import "YYViewController.h"10 11 @interface YYViewController ()12 /**13 * 文本輸入框14 */15 @property (strong, nonatomic) IBOutlet UITextField *textfield;16 17 @end18 19 @implementation YYViewController20 21 - (void)viewDidLoad22 {23 [super viewDidLoad];24 //125 //添加一個時間選取器26 UIDatePicker *date=[[UIDatePicker alloc]init];27 /**28 * 設定只顯示中文29 */30 [date setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];31 /**32 * 設定只顯示日期33 */34 date.datePickerMode=UIDatePickerModeDate;35 // [self.view addSubview:date];36 37 //當游標移動到文字框的時候,召喚時間選取器38 self.textfield.inputView=date;39 40 //241 //建立工具條42 UIToolbar *toolbar=[[UIToolbar alloc]init];43 //設定工具條的顏色44 toolbar.barTintColor=[UIColor brownColor];45 //設定工具條的frame46 toolbar.frame=CGRectMake(0, 0, 320, 44);47 48 //給工具條添加按鈕49 UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一個" style:UIBarButtonItemStylePlain target:self action:@selector(click) ];50 51 UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一個" style:UIBarButtonItemStylePlain target:self action:@selector(click)];52 53 UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];54 UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(click)];55 56 toolbar.items = @[item0, item1, item2, item3];57 //設定文本輸入框鍵盤的輔助視圖58 self.textfield.inputAccessoryView=toolbar;59 }60 -(void)click61 {62 NSLog(@"toolbar");63 }64 @end
實現效果:
二、UITool Bar在上面可以添加子控制項TOOLBAR中只能添加UIBarButtonItem子控制項,其他子控制項會被封裝秤這種類型的上面的控制項依次排放(空格————)有樣式,可以指定樣式(可展開的),一般用來做工具列。 使用toolbar做點菜的頭部標題如何讓點菜系統置中?在ios6中是正的,在ios7中是歪的在自訂鍵盤上加上一個工具列。數組裡什麼順序放的,就按照什麼順序顯示
1 toolbar.items = @[item0, item1, item2, item3];2 //設定文本輸入框鍵盤的輔助視圖3 self.textfield.inputAccessoryView=toolbar;
iOS開發UI篇—Date Picker和UITool Bar控制項簡單介紹