#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController<UITextFieldDelegate>
{
UITextField *textField1;
UITextField *textField2;
UISegmentedControl *_prevNext;
}
- (UIToolbar *)createActionBar;
@end
//
// FirstViewController.m
// MyTableViewDemo
//
// Created by Chocolate on 13-9-12.
// Copyright (c) 2013年 Chocolate. All rights reserved.
// #import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad]; textField1 = [[UITextField alloc]initWithFrame:CGRectMake(, , , )];
[textField1 setBorderStyle:UITextBorderStyleRoundedRect];
[textField1 setReturnKeyType:UIReturnKeyNext];
[textField1 setDelegate:self];
textField2.inputAccessoryView = [self createActionBar];
[textField1 setTag:];
[textField1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[self.view addSubview:textField1]; textField2 = [[UITextField alloc]initWithFrame:CGRectMake(, , , )];
[textField2 setBorderStyle:UITextBorderStyleRoundedRect];
[textField2 setReturnKeyType:UIReturnKeyDone];
[textField2 setDelegate:self];
textField2.inputAccessoryView = [self createActionBar];
[textField2 setTag:];
[textField2 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[self.view addSubview:textField2];
} - (BOOL)textFieldShouldReturn:(UITextField *)textField
{
switch (textField.tag) {
case :
[textField2 becomeFirstResponder];
break;
case :
[textField2 resignFirstResponder];
break;
default:
break;
}
return YES;
} -(UIToolbar *)createActionBar {
UIToolbar *actionBar = [[UIToolbar alloc] init];
actionBar.translucent = YES;
[actionBar sizeToFit];
actionBar.barStyle = UIBarStyleBlackTranslucent; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"")
style:UIBarButtonItemStyleDone target:self
action:@selector(handleActionBarDone:)]; _prevNext = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", @""), NSLocalizedString(@"Next", @""), nil]];
_prevNext.momentary = YES;
_prevNext.segmentedControlStyle = UISegmentedControlStyleBar;
_prevNext.tintColor = actionBar.tintColor;
[_prevNext addTarget:self action:@selector(handleActionBarPreviousNext:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *prevNextWrapper = [[UIBarButtonItem alloc] initWithCustomView:_prevNext];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[actionBar setItems:[NSArray arrayWithObjects:prevNextWrapper, flexible, doneButton, nil]]; return actionBar;
} - (void)handleActionBarPreviousNext:(UISegmentedControl *)control
{
const BOOL isNext = control.selectedSegmentIndex == ;
if (isNext) {
NSLog(@"next");
} else {
NSLog(@"previous");
}
[control setSelectedSegmentIndex:UISegmentedControlNoSegment];
} - (BOOL)handleActionBarDone:(UIBarButtonItem *)doneButton { return NO;
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

ios 给键盘上面加上“完成”的更多相关文章

  1. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  2. iOS 收起键盘的几种方式

    iOS 收起键盘的几种方式 1.一般的view上收起键盘 // 手势 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ ...

  3. ios 自定义键盘

    由于项目需要,需要自定义键盘.ios系统键盘会缓存键盘输入,并保存在系统目录下的文件里,并且是明文存储,存在帐号密码泄漏风险.在别人代码基础上修改了下,美化了下界面,去掉了字符输入,加了点击特效,截图 ...

  4. IOS 回收键盘通用代码

    感觉IOS的键盘回收好累,所以封装了一个通用一点的方法 -(IBAction)spbResignFirstResponder:(id)sender { // NSLogObj(sender); if ...

  5. iOS学习——键盘弹出遮挡输入框问题解决方案

    在iOS或Android等移动端开发过程中,经常遇到很多需要我们输入信息的情况,例如登录时要输入账号密码.查询时要输入查询信息.注册或申请时需要填写一些信息等都是通过我们键盘来进行输入的,在iOS开发 ...

  6. iOS 解决键盘挡住输入框的问题

    iOS开发中经常会用到输入框UITextField,所以也常会遇到键盘挡住输入框而看不到输入框的内容. 在这里记录一种方法,用UITextField的代理来实现View的上移来解决这个问题. 首先设置 ...

  7. ios键盘弹起 body的高度拉长,页面底部空白问题。ios软键盘将页面抵到上面后,关闭软键盘页面不回弹的问题。

    js 监听ios手机键盘弹起和收起的事件 /* js 监听ios手机键盘弹起和收起的事件 */ document.body.addEventListener('focusin', () => { ...

  8. ios处理键盘的大小

    iOS的键盘有几个通知 UIKeyboardWillShowNotification UIKeyboardDidShowNotification UIKeyboardWillHideNotificat ...

  9. IOS第12天(4,作业弹出键盘上加上(xib)view的处理,时间选择,代理模式使用,键盘的监听 )

    *****HMViewController.m #import "HMViewController.h" #import "HMKeyboardTool.h" ...

随机推荐

  1. 网络配置vlan

    1. # This file describes the network interfaces available on your system # and how to activate them. ...

  2. rails rake 版本问题

    rails rake 版本问题 通常情况下,如果我们电脑上同时装了不同版本的rake时,运行rake命令时会出错,如: rake db:migrate rake aborted! You have a ...

  3. FATAL ERROR: Could not find ./bin/my_print_defaults 解决方法

    FATAL ERROR: Could not find ./bin/my_print_defaults If you compiled from source, you need to run 'ma ...

  4. seo 基础

    标题用<h2>标题</h2>  iamge  中加上 alt=“”   的属性 这样有利用百度的搜索引擎爬虫搜索到

  5. variable `xxx' has initializer but incomplete type

    错误:variable `xxx' has initializer but incomplete type 原因:xxx对应的类型没有找到,只把xxx声明了但是没给出定义.编译器无从确认你调用的构造函 ...

  6. Java泛型函数的运行时类型检查的问题

    在一个数据持久化处理中定义了数据保存和读取的 泛型函数的,但是在运行时出现类型转换错误,类型不匹配,出错的位置不是load方法,而是在调用load方法之后,得到了列表数据,对列表数据进行使用时出现的. ...

  7. 10个最佳的触控手式的JavaScript框架(转)

    由于各种原因移动开发是一项艰难的工作,比如它是非常耗时的.充满压力的任务.最重要的是,作为一个开发人员,你必须保持更新所有最新 的技术和技巧——你必须知道所有最新的趋势,问题和解决方案等.例如跨浏览器 ...

  8. Mysql中Innodb大量插入数据时SQL语句的优化

    innodb优化后,29小时入库1300万条数据 参考:http://blog.51yip.com/mysql/1369.html 对于Myisam类型的表,可以通过以下方式快速的导入大量的数据: A ...

  9. 资深投资人全力反击: VC增值平台从来就不是一坨狗屎

    编者注: 本文来自海外著名科技博客VentureBeat, 英文原文出自Kyle Lacy之手 ,中文版由天地会珠海分舵进行编译. 文章主要是针对前几天德国VC Christian Claussen的 ...

  10. day21<IO流+&FIle递归>

    IO流(字符流FileReader) IO流(字符流FileWriter) IO流(字符流的拷贝) IO流(什么情况下使用字符流) IO流(字符流是否可以拷贝非纯文本的文件) IO流(自定义字符数组的 ...