标签:
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UITextField *textfield;
@end
@implementation ViewController
- (void)viewDidLoad {
UIDatePicker *date=[[UIDatePicker alloc]init];
//设置只显示中文
[date setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
//只显示日期
date.datePickerMode=UIDatePickerModeDate;
//当光标移到文本框时召唤时间选择器
self.textfield.inputView=date;
//创建工具条,设置工具条的颜色和frame
UIToolbar *toorbar=[[UIToolbar alloc]init];
toorbar.barTintColor=[UIColor orangeColor];
toorbar.frame=CGRectMake(0, 0, 375, 44);
//给工具条添加按钮
UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"上" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithTitle:@"下" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
UIBarButtonItem *item4=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
toorbar.items=@[item1,item2,item3,item4];
//设置文本输入框键盘的辅助视图
self.textfield.inputAccessoryView=toorbar;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)click
{
NSLog(@"实现跳转");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
标签:
原文地址:http://www.cnblogs.com/linximu/p/4417486.html