#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. DBA不可不知的操作系统内核参数

    背景 操作系统为了适应更多的硬件环境,许多初始的设置值,宽容度都很高. 如果不经调整,这些值可能无法适应HPC,或者硬件稍好些的环境. 无法发挥更好的硬件性能,甚至可能影响某些应用软件的使用,特别是数 ...

  2. kettle的jndi的使用

    kettle可以使用jdbc的方式设置job或者tansform的数据库连接,但是,同时它也支持JNDI方式连接数据库,后者更加方便,只需要配置一份配置文件就可以了,不用每个DBConnection都 ...

  3. GridView截取某一列字符串的长度

    Gridview中,如果你的某一列字符串的长度过长,不做处理的话.那么将显示的奇丑无比, 可以采取设置样式,将其显示为定长,可以在点击查看的时候,在另一个页面对其进行显示 首先在前台设置样式 < ...

  4. HTML坦克大战学习02---坦克动起来

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  5. 关于Cocos2d-x的数据存储

    Cocos2d-x对数据的存储没有用到数据库,但是有用到一个类似数据库的小型数据库,就是数据存储.存储后的数据用XML的文件格式保存在C:\Users\Administrator\AppData\Lo ...

  6. TensorFlow基础笔记(13) Mobilenet训练测试mnist数据

    主要是四个文件 mnist_train.py #coding: utf-8 import os import tensorflow as tf from tensorflow.examples.tut ...

  7. C++函数类型

    继续上一篇 #include <iostream> using namespace std; void swap1(int &v1, int &v2); typedef v ...

  8. Checked Exception & Unchecked Exception

    查Spring事务管理时看到一句话: Spring使用声明式事务处理,默认情况下,如果被注解的数据库操作方法中发生了unchecked异常,所有的数据库操作将rollback:如果发生的异常是chec ...

  9. (转) 从ffmpeg中提取出YUV数据

    有时需要从ffmpeg中提取出YUV数据用作预览,另存什么的. ffmpeg是先解码成YUV, 再以这个YUV作为输入进行编码,所以YUV数据有两种:  解码后的YUV数据, 以及  编码重建的YUV ...

  10. Python脚本完美解决Linux环境解压.zip文件乱码问题

    1.vi uzip(文件名)2.复制以下Python程序 #!/usr/bin/env python # -*- coding: utf-8 -*- # uzip.py import os impor ...