iOS--inputView和inputAccessoryView
iOS–inputView和inputAccessoryView
什么是inputView和inputAccessoryView?
如果是UITextField和UITextView,下面是声明文件源代码:
// set while first responder, will not take effect until reloadInputViews is called.
@property (readwrite, retain) UIView *inputView;
@property (readwrite, retain) UIView *inputAccessoryView;
如果是其他的控件,继承了UIResponder,(UIView 是UIResponder的子类),下面是声明文件源代码:
// Called and presented when object becomes first responder. Goes up the responder chain.
@property (nonatomic, readonly, retain) UIView *inputView NS_AVAILABLE_IOS(3_2);
@property (nonatomic, readonly, retain) UIView *inputAccessoryView NS_AVAILABLE_IOS(3_2);
自定义TextField或TextView
自定义只需要重写下面的两个属性
textField.inputView = [UIView alloc] init];
textField.inputAccessoryView = [UIToolbar alloc] init];
自定义继承了UIResponder类的控件
需要自定义UIResponder的子类,我们需要在重新定义一个子类,然后再这个子类中声明inputView,inputAccessoryView为可读可写属性。然后重写getter方法。同时还需要覆盖-(BOOL)canBecomeFirstResponder方法。
下面以UIButton为例子的子类重设代码:
#import <UIKit/UIKit.h>
@interface ABEButton : UIButton
@property (nonatomic, strong)UIToolbar *inputAccessoryView;
@property (nonatomic, strong)UIView *inputView;
@end
#import "ABEButton.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
@implementation ABEButton
-(BOOL)canBecomeFirstResponder
{
return YES;
}
#pragma mark- Getter, Setter
- (UIView*)inputView{
if (!_inputView) {
_inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220)];
_inputView.backgroundColor = [UIColor redColor];
}
return _inputView;
}
- (UIToolbar*)inputAccessoryView{
if (!_inputAccessoryView) {
_inputAccessoryView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
_inputAccessoryView.backgroundColor = [UIColor grayColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"隐藏" style:UIBarButtonItemStylePlain target:self action:@selector(clickFinishButton:)];
_inputAccessoryView.items = @[item];
}
return _inputAccessoryView;
}
#pragma mark- Private method
- (void)clickFinishButton:(ABEButton*)buttonItem{
[self resignFirstResponder];
}
@end
这样,我们就可以使用点击button,弹出inputView了。
注意:不要忘记为button添加becomeFirstResponder。
iOS--inputView和inputAccessoryView的更多相关文章
- iOS开发小技巧--iOS键盘 inputView 和 inputAccessoryView
iOS键盘 inputView 和 inputAccessoryView 1.inputAccessoryView UITextFields和UITextViews有一个inputAccessoryV ...
- iOS开发inputView和inputAccessoryView
1.简介 起初看到这两个属性是在UIResponder中,只是可读的: @property (nullable, nonatomic, readonly, strong) __kindof UIVie ...
- 【iOS发展-70】点菜系统案例:使用文本框inputView和inputAccessoryView串联UIPickerView、UIDatePicker和UIToolBar
(1)效果 (2)先在storyboard中设计界面,然后源码(直接在ViewController中码) #import "ViewController.h" @interface ...
- inputAccessoryView,inputView
我们在使用UITextView和UITextField的时候,可以通过它们的inputAccessoryView属性给输入时呼出的键盘加一个附属视图,通常是UIToolBar,用于回收键盘. 但是当我 ...
- iOS 7 隐藏特性
当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...
- ios之键盘的自定义
一.键盘通知 当文本View(如UITextField,UITextView,UIWebView内的输入框)进入编辑模式成为first responder时,系统会自动显示键盘.成为firstresp ...
- 对于iOS 7 隐藏特性和解决之道
当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...
- UIResponder
原网址:http://www.cnblogs.com/kuku/archive/2011/11/12/2246389.html 在 iOS 中,一个 UIResponder 对象表示一个可以接收触摸屏 ...
- 你真的了解UITextField吗?
一:首先查看一下关于UITextField的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextIn ...
随机推荐
- 【读书笔记】【CLR via C#】【第一章】The CLR’s Execution Model
内容提要 本章的目的是对.Net 框架的设计做一个总体的介绍,包括介绍框架中使用的一些技术.定义一些术语.同时会展示从源代码生成应用程序(或者一些包含了一些自定义类型的可以发布的组件),并且会解释程序 ...
- Phonegap 3.0 设置APP是否全屏
Phonegap 3.0 默认是全屏,如需要取消全屏,可手动修改config, 在APP/res/xml/config.xml文件可设置preference: <?xml version='1. ...
- 7.微软AJAX的解决方案
Asp.net中内置的简化AJAX开发的控件UpdatePanel非常方便,但是它会带了许多viewstate,所以高手们并不喜欢它.但它开发在内网应用时可以考滤 放入ScriptManager,将要 ...
- RESTful风格的Web服务框架:Swagger
Swagger与SpringMVC项目整合 为了方便的管理项目中API接口,在网上找了好多关于API接口管理的资料,感觉目前最流行的莫过于Swagger了,功能强大,UI界面漂亮,并且支持在线测试等等 ...
- 全表扫描出现db file sequential read
SESSION 1执行 SQL> update test1 set id=1000; SESSION 2 : select * from test1 如果表上面有大量的行迁链接,会是单块读等待事 ...
- Linux os
进程就是处于执行期的程序(目标代码存放在某种存储介质上,如内存).进程不只局限于可执行代码,还包括其他资源:打开的文件,挂起的信号,内核数据结构,内存地址空间以及至少一个执行线程. 进程是出于执行期的 ...
- Executors常用的创建ExecutorService的几个方法说明
一.线程池的创建 我们可以通过ThreadPoolExecutor来创建一个线程池. new ThreadPoolExecutor(corePoolSize, maximumPoolSize, kee ...
- .net framework client profile
.NET Framework Client Profile The .NET Client Profile is a subset of the .NET Framework, which was p ...
- wcf中 生成x5.09证书的工具
原文链接http://blog.pluralsight.com/selfcert-create-a-self-signed-certificate-interactively-gui-or-progr ...
- WordPress Simple Login Registration插件’username‘参数跨站脚本漏洞
漏洞名称: WordPress Simple Login Registration插件’username‘参数跨站脚本漏洞 CNNVD编号: CNNVD-201308-519 发布时间: 2013-0 ...