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 ...
随机推荐
- css的继承、层叠和特殊性
1,继承 css的某些样式是具有继承性的,那么什么是继承呢?继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代. 但注意有一些css样式是不具有继承性的.如border: ...
- 浙工大C语言入门指南 (仅供参考)
C语言书籍推荐 浙工大图书馆中,计算机的书都集中在三楼TP区.我个人推荐下面这么几本书. <Head First C>.Head First系列的书质量基本都很高.该书有很多插图,总体上就 ...
- INI解析模块的C++实现
INI文件格式是某些平台或软件上的配置文件的非正式标准,以节(section)和键(key)构成,常用于微软Windows操作系统中. 节(section) 节用方括号括起来,单独占一行,例如: [s ...
- dispatch队列
GCD编程的核心就是dispatch队列,dispatch block的执行最终都会放进某个队列中去进行,它类似NSOperationQueue但更复杂也更强大,并且可以嵌套使用.所以说,结合bloc ...
- E: Write error - write (28 No space left on device)
1:在终端中运行cd命令,提示: e: Write error - write (28 No space left on device) E: Cant mmap an empty file 2:使用 ...
- Hibernate 使用HQL的 in 时要注意判断in的值(list)是否包含数据
如果你使用 HQL的 in,例如: sessionFactory.getCurrentSession() .createQuery("select hlInfo.id, count(id) ...
- wcf中的File-less Activation
File-less Activation Although .svc files make it easy to expose WCF services, an even easier approac ...
- bzoj1260
很容易脑补出来的区间dp O(n3)的 var f:array[0..51,0..51] of longint; i,n,j,l,k:longint; s:string; function ...
- 【转】微信Android SDK示例代码及运行方法
原文网址:http://blog.csdn.net/icyfox_bupt/article/details/23742217 最近在研究微信SDK,无奈网上好使的教程太少,对于程序员来说最好的东西,一 ...
- 【转】怎么在Foxmail回复/转发时使用签名?
原文网址:http://kf.qq.com/faq/120322fu63YV130422yABZRZ.html Foxmail回复/转发时使用签名,可通过在模版中设置签名.如下版本操作方法: 一.fo ...