//
// YYViewController.m
// datepicker
//
// Created by apple on 14-6-3.
// Copyright (c) 2014年 itcase. All rights reserved.
//ios
#import "YYViewController.h"數組
@interface YYViewController ()
/**
* 文本輸入框
*/
@property (strong, nonatomic) IBOutlet UITextField *textfield;app
@end工具
@implementation YYViewControllerpost
- (void)viewDidLoad
{
[super viewDidLoad];
//1
//添加一個時間選擇器
UIDatePicker *date=[[UIDatePicker alloc]init];
/**
* 設置只顯示中文
*/
[date setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
/**
* 設置只顯示日期
*/
date.datePickerMode=UIDatePickerModeDate;
// [self.view addSubview:date];
//當光標移動到文本框的時候,召喚時間選擇器
self.textfield.inputView=date;
//2
//建立工具條
UIToolbar *toolbar=[[UIToolbar alloc]init];
//設置工具條的顏色
toolbar.barTintColor=[UIColor brownColor];
//設置工具條的frame
toolbar.frame=CGRectMake(0, 0, 320, 44);
//給工具條添加按鈕
UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一個" style:UIBarButtonItemStylePlain target:self action:@selector(click) ];
UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一個" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
toolbar.items = @[item0, item1, item2, item3];
//設置文本輸入框鍵盤的輔助視圖
self.textfield.inputAccessoryView=toolbar;
}
-(void)click
{
NSLog(@"toolbar");
}
@endatom
實現效果:spa