IOS UI-键盘处理和UIToolbar

时间:2020-12-20 21:03:58
 //
// ViewController.m
// IOS_0225-键盘处理和UIToolBar
//
// Created by ma c on 16/2/25.
// Copyright © 2016年 博文科技. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UITextField *textField; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor cyanColor]; [self createTextField];
} - (void)createTextField
{
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(, , , 44.0)];
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.placeholder = @"请输入内容";
self.textField.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.textField]; //自定义文本框的键盘
self.textField.inputView = [UIButton buttonWithType:UIButtonTypeContactAdd];
//自定义文本框上面的辅助工具控件
UIToolbar *toolBar = [[UIToolbar alloc] init];
[toolBar sizeToFit];
toolBar.barTintColor = [UIColor redColor]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previewClick)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(nextClick)];
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneClick)];
toolBar.items = @[item1,item2,item3,item4];
self.textField.inputAccessoryView = toolBar; } - (void)previewClick
{
NSLog(@"上一个");
} - (void)nextClick
{
NSLog(@"下一个");
} - (void)doneClick
{
[self.view endEditing:YES];
} @end