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" ...
随机推荐
- thymeleaf+bootstrap,onclick传参实现模态框中遇到的错误
一个困扰了N久的问题... 网上大多帖子是这么写的 onclick调javascript函数时,不能直接使用onclick=“editUser(${prod.id})”,这样会报错,需要修改成如下的格 ...
- GridView截取某一列字符串的长度
Gridview中,如果你的某一列字符串的长度过长,不做处理的话.那么将显示的奇丑无比, 可以采取设置样式,将其显示为定长,可以在点击查看的时候,在另一个页面对其进行显示 首先在前台设置样式 < ...
- R语言低级绘图函数-title
title 函数用来在一张图表上添加标题 基本用法: main 表示主标题,通常位于图像的上方, sub 表示副标题,位于图像的下方, xlab 表示x轴的标签,ylab 表示y轴的标签 par(om ...
- CentOS7下Tomcat启动慢的原因及解决方案
现象 在一次CentOS 7系统中安装Tomcat,启动过程很慢,需要几分钟,经过查看日志,发现耗时在这里:是session引起的随机数问题导致的.Tocmat的Session ID是通过SHA1算法 ...
- js 离开页面
序言 大家是否经常遇到在关闭网页的时候,会看到一个确定是否离开当前页面的提示框?想一些在线测试系统.信息录入系统等就经常会有这一些提示,避免用户有意或者无意中关掉了页面,导致数据丢失.这里面的实现过程 ...
- 解决 SharePoint 2010 拒绝访问爬网内容源错误的小技巧(禁用环回请求的两种方式)
这里有一条解决在SharePoint 2010搜索爬网时遇到的“拒绝访问错误”的小技巧. 首先要检查默认内容访问帐户是否具有相应的访问权限,或者添加一条相应的爬网规则.如果目标资源库是一个ShareP ...
- 《R语言入门》语言及环境简单介绍
简单介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- Java类的设计----多态性及其应用
多态性及其应用 多态性 多态—在Java中,子类的对象可以替代父类的对象使用一个变量只能有一种确定的数据类型一个引用类型变量可能指向(引用)多种不同类型的对象 Person p = new Stude ...
- 使用select多选标签笔记
之前一直用checkbox做多选,其实 select也可以多选,只要多给一个属性即可.标签属性 http://www.w3school.com.cn/tags/att_select_multiple. ...
- [转载]2014年10月26完美世界校招两道java题
public class VolitileTest { volatile static int count=0; public static void main(String args[]){ for ...