iOS自定义键盘输入样式(设置成时间选择器等)

来源:互联网 发布:梦想小镇绿钞淘宝 编辑:程序博客网 时间:2024/05/20 07:50
////  ViewController.m//  自定义键盘输入样式Input////  Created by linwenbang on 15/4/23.//  Copyright (c) 2015年 linwenbang. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UITextField *inputField;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        UIDatePicker *picker = [[UIDatePicker alloc] init];        picker.datePickerMode = UIDatePickerModeDate;        picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];    
    //设置键盘内容为自定义样式    self.inputField.inputView = picker;        UIToolbar *tool = [[UIToolbar alloc] init];    tool.frame = CGRectMake(0, 0, 320, 44);    tool.barTintColor = [UIColor blueColor];        UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(prvItem)];        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(prvItem)];        //添加弹簧进行占位,使最后的一个按钮靠右    UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];        UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(finish)];        //bar只能添加UIBarButtonItem控件    tool.items = @[item1,item2,item3,item4];    self.inputField.inputAccessoryView = tool;    }- (void)prvItem{    NSLog(@"点击了上一个");}- (void)finish{    NSLog(@"点击了完成");        [self.view endEditing:YES];}@end

0 0
原创粉丝点击