ios 给键盘上面加上“完成”
#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 给键盘上面加上“完成”的更多相关文章
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS 收起键盘的几种方式
iOS 收起键盘的几种方式 1.一般的view上收起键盘 // 手势 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ ...
- ios 自定义键盘
由于项目需要,需要自定义键盘.ios系统键盘会缓存键盘输入,并保存在系统目录下的文件里,并且是明文存储,存在帐号密码泄漏风险.在别人代码基础上修改了下,美化了下界面,去掉了字符输入,加了点击特效,截图 ...
- IOS 回收键盘通用代码
感觉IOS的键盘回收好累,所以封装了一个通用一点的方法 -(IBAction)spbResignFirstResponder:(id)sender { // NSLogObj(sender); if ...
- iOS学习——键盘弹出遮挡输入框问题解决方案
在iOS或Android等移动端开发过程中,经常遇到很多需要我们输入信息的情况,例如登录时要输入账号密码.查询时要输入查询信息.注册或申请时需要填写一些信息等都是通过我们键盘来进行输入的,在iOS开发 ...
- iOS 解决键盘挡住输入框的问题
iOS开发中经常会用到输入框UITextField,所以也常会遇到键盘挡住输入框而看不到输入框的内容. 在这里记录一种方法,用UITextField的代理来实现View的上移来解决这个问题. 首先设置 ...
- ios键盘弹起 body的高度拉长,页面底部空白问题。ios软键盘将页面抵到上面后,关闭软键盘页面不回弹的问题。
js 监听ios手机键盘弹起和收起的事件 /* js 监听ios手机键盘弹起和收起的事件 */ document.body.addEventListener('focusin', () => { ...
- ios处理键盘的大小
iOS的键盘有几个通知 UIKeyboardWillShowNotification UIKeyboardDidShowNotification UIKeyboardWillHideNotificat ...
- IOS第12天(4,作业弹出键盘上加上(xib)view的处理,时间选择,代理模式使用,键盘的监听 )
*****HMViewController.m #import "HMViewController.h" #import "HMKeyboardTool.h" ...
随机推荐
- ubuntu 16.04 安装pycharm
Ubuntu16.04下安装Cuda8.0+Caffe+TensorFlow-gpu+Pycharm过程(Simple) ubuntu 16.04 安装pycharm 1.安装java jdk 直接 ...
- python读写word文档
读: from docx import Document dir_docx = 'F:\Eclipse\workspace\Spider\cnblogs_doc\mytest - 副本.docx' d ...
- e650. 激活事件
An object wishing to fire item events must implement ItemSelectable. This example shows typical code ...
- 在 Mac 上搭建 Nginx PHP Mysql 开发环境
事实上这个过程跟Linux下安装都几乎相同,仅仅是部分命令有区别,大同小异. 网上看到非常多教程都是用 brew 之类的包管理器安装,可是 Mac 自带了 php , 难道还要再装一个第三方的?强迫症 ...
- 剑指offer_面试题5_从尾到头打印链表(栈和递归实现)
题目:输入一个链表的头结点,从尾到头反过来打印出每一个节点的值 考察 单链表操作.栈.递归等概念. 理解:要实现单链表的输出,那么就须要遍历.遍历的顺序是从头到尾.而节点输出的顺序是从尾到头.因此,先 ...
- haproxy+keepalived实现web集群高可用性[转]
负载均衡集群的概念 负载均衡是设计分布式系统架构必须要考虑的因素之一,它指的是通过调度分发的方式尽可能将“请求”.“访问”的压力负载平均分摊到集群中的各个节点,避免有些节点负载太高导致访问延迟,而有些 ...
- Spring-JDBC配置
以C3P0连接池为例:由于C3P0是第三方,我们无法使用注解将其定义为bean,因此需要在applicationContext.xml中配置: <!-- 导入配置文件 --> <co ...
- MathType公式编辑器快捷键操作
快捷键操作是最常见的操作方式,MathType软件系统提供大量的快捷键操作供用户使用.使用MathType公式编辑器快捷键操作可节省大量的操作的时间,本教程将详解MathType快捷键操作. 放大或缩 ...
- phpcms v9如何更改分页显示条数?
默认显示页码数有10条,比如想更改成显示3条,例如这样 上一页 1 2 3...34 下一页 更改phpcms\libs\functions\global.func.php,找到分页函数,大概在665 ...
- mysql优化方法积累
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...