第九篇 - UITextField
初始化
UITextField *tf = [[UITextField alloc] init];
typedef NS_ENUM(NSInteger, UITextBorderStyle) {//没有任何边框 UITextBorderStyleNone,//线性边框 UITextBorderStyleLine,//阴影效果边框 UITextBorderStyleBezel,//原型效果边框 UITextBorderStyleRoundedRect };typedef NS_ENUM(NSInteger, UITextFieldViewMode) {//从不显示 UITextFieldViewModeNever,//编辑的时候显示 UITextFieldViewModeWhileEditing,//非编辑的时候显示 UITextFieldViewModeUnlessEditing,//任何时候都显示 UITextFieldViewModeAlways }; // //NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextInput, NSCoding> // //获取和设置文字@property(nullable, nonatomic,copy) NSString *text; // default is nil //获取和设置富文本@property(nullable, nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil //文字的颜色@property(nullable, nonatomic,strong) UIColor *textColor; // default is nil. use opaque black // 文字的font@property(nullable, nonatomic,strong) UIFont *font; // default is nil. use system font 12 pt //对齐方式@property(nonatomic) NSTextAlignment textAlignment; // default is NSLeftTextAlignment //边框样式@property(nonatomic) UITextBorderStyle borderStyle; // default is UITextBorderStyleNone. If set to UITextBorderStyleRoundedRect, custom background images are ignored. //文字的大小,颜色等属性统一设置,影响较广泛,(全局)@property(nonatomic,copy) NSDictionary<NSString *, id> *defaultTextAttributes NS_AVAILABLE_IOS(7_0); // applies attributes to the full range of text. Unset attributes act like default values. // //占位文字@property(nullable, nonatomic,copy) NSString *placeholder; // default is nil. string is drawn 70% gray //富文本占位文字@property(nullable, nonatomic,copy) NSAttributedString *attributedPlaceholder NS_AVAILABLE_IOS(6_0); // default is nil // 编辑完一次后,再次回来编辑会清空上次编辑的所有内容(为yes时)@property(nonatomic) BOOL clearsOnBeginEditing; // default is NO which moves cursor to location clicked. if YES, all text cleared //自动调整字体大小@property(nonatomic) BOOL adjustsFontSizeToFitWidth; // default is NO. if YES, text will shrink to minFontSize along baseline //字体最小值(自动调整时)@property(nonatomic) CGFloat minimumFontSize; // default is 0.0. actual min may be pinned to something readable. used if adjustsFontSizeToFitWidth is YES //代理@property(nullable, nonatomic,weak) id<UITextFieldDelegate> delegate; // default is nil. weak reference //背景图片(会拉伸)@property(nullable, nonatomic,strong) UIImage *background; // default is nil. draw in border rect. image should be stretchable //不可用时背景图片@property(nullable, nonatomic,strong) UIImage *disabledBackground; // default is nil. ignored if background not set. image should be stretchable // //是否在编辑状态@property(nonatomic,readonly,getter=isEditing) BOOL editing; //是否允许更改字符属性字典@property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0); // default is NO. allows editing text attributes with style operations and pasting rich text //设置属性字典@property(nullable, nonatomic,copy) NSDictionary<NSString *, id> *typingAttributes NS_AVAILABLE_IOS(6_0); // automatically resets when the selection changes // //// You can supply custom views which are displayed at the left or right //// sides of the text field. Uses for such views could be to show an icon or //// a button to operate on the text in the field in an application-defined //// manner. //// //// A very common use is to display a clear button on the right side of the //// text field, and a standard clear button is provided. // //设置清除按钮的显示模式@property(nonatomic) UITextFieldViewMode clearButtonMode; // sets when the clear button shows up. default is UITextFieldViewModeNever // //设置输入框左边的view@property(nullable, nonatomic,strong) UIView *leftView; // e.g. magnifying glass //设置输入框左视图的显示模式@property(nonatomic) UITextFieldViewMode leftViewMode; // sets when the left view shows up. default is UITextFieldViewModeNever // @property(nullable, nonatomic,strong) UIView *rightView; // e.g. bookmarks button@property(nonatomic) UITextFieldViewMode rightViewMode; // sets when the right view shows up. default is UITextFieldViewModeNever // //// drawing and positioning overrides // - (CGRect)borderRectForBounds:(CGRect)bounds;- (CGRect)textRectForBounds:(CGRect)bounds;- (CGRect)placeholderRectForBounds:(CGRect)bounds;- (CGRect)editingRectForBounds:(CGRect)bounds;- (CGRect)clearButtonRectForBounds:(CGRect)bounds;- (CGRect)leftViewRectForBounds:(CGRect)bounds;- (CGRect)rightViewRectForBounds:(CGRect)bounds; // - (void)drawTextInRect:(CGRect)rect;- (void)drawPlaceholderInRect:(CGRect)rect; // //// Presented when object becomes first responder. If set to nil, reverts to following responder chain. If //// set while first responder, will not take effect until reloadInputViews is called. //设置输入框成为第一响应时弹出的视图和辅助视图(类似键盘)@property (nullable, readwrite, strong) UIView *inputView; //键盘上的bar(辅助工具条)@property (nullable, readwrite, strong) UIView *inputAccessoryView; // //这个属性设置是否允许再次编辑时在内容中间插入内容@property(nonatomic) BOOL clearsOnInsertion NS_AVAILABLE_IOS(6_0); // defaults to NO. if YES, the selection UI is hidden, and inserting text will replace the contents of the field. changing the selection will automatically set this to NO. // @end // @interface UIView (UITextField)- (BOOL)endEditing:(BOOL)force; // use to make the view or any subview that is the first responder resign (optionally force)@end // @protocol UITextFieldDelegate <NSObject> // @optional // //点击输入框时触发的方法,返回YES则可以进入编辑状态,NO则不能。- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing. //开始编辑时调用的方法- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder //将要结束编辑时调用的方法,返回YES则可以结束编辑状态,NO则不能- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end //结束编辑调用的方法- (void)textFieldDidEndEditing:(UITextField *)textField; // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called // //输入字符时调用的方法- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text // //点击清除按钮时调用的函数,返回YES则可以清除,点击NO则不能清除- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO to ignore (no notifications) //点击return键触发的函数- (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO to ignore. // @end// //NS_ASSUME_NONNULL_END
键盘代理
2016-03-18 07:54:42.866 UITextField[2479:169303] -[ViewController textFieldShouldBeginEditing:]
2016-03-18 07:54:42.880 UITextField[2479:169303] -[ViewController textFieldDidBeginEditing:]
2016-03-18 07:54:46.215 UITextField[2479:169303] -[ViewController textField:shouldChangeCharactersInRange:replacementString:]
2016-03-18 07:54:48.893 UITextField[2479:169303] -[ViewController textField:shouldChangeCharactersInRange:replacementString:]
2016-03-18 07:54:51.012 UITextField[2479:169303] -[ViewController textField:shouldChangeCharactersInRange:replacementString:]
2016-03-18 07:54:53.368 UITextField[2479:169303] -[ViewController textFieldShouldEndEditing:]
2016-03-18 07:54:53.375 UITextField[2479:169303] -[ViewController textFieldDidEndEditing:]
转载于:https://www.cnblogs.com/kinghx/p/5290688.html
第九篇 - UITextField相关推荐
- CCIE理论-第九篇-IPV6详细介绍
CCIE理论-第九篇-IPV6介绍 应该有人等这个好久了 其实这个可以放NA,可以放NP,也可以放IE 放在这,其实也没啥了,开搞吧! IPV6-VS-IPV4 ipv6对比ipv4最大的区别是,最明 ...
- 学习 spring-cloud-aibaba第九篇,综合应用微信小程序《背诗词》
文章目录 1.背诗词小程序界面和功能点 1.1 界面展示 1.2 功能介绍 2.架构图 2.1 理想中架构图 2.2 实际上的架构图 3 代码开源 4 线上体验 5.披过的荆斩过的棘 6.存在的不足 ...
- 相亲网站平台制作建设,第九篇
多语言交友婚恋相亲平台开发,第九篇,也是后台篇,从这篇开始,主要开始记录后台的功能和的操作部分等. 如果有什么问题需要咨询的,可以加我的扣236-0248-666 这个是预览截图效果 网站设置 cla ...
- 服务拆分的设计和思考(B2B 技术共享第九篇)
本文主要想给大家分享一下,宋小菜这三年来,是如何从单点巨石系统演变成领域驱动的服务化设计的.这个演变现在还在继续,我们在实践过程中遇到了很多坑,也收获了经验和思考. 一.早期的系统 1.1 唯快不破 ...
- java语言程序设计郑莉课后答案_java语言程序设计郑莉第九篇课后习题答案.docx...
java语言程序设计郑莉第九篇课后习题答案.docx 还剩 36页未读, 继续阅读 下载文档到电脑,马上远离加班熬夜! 亲,很抱歉,此页已超出免费预览范围啦! 如果喜欢就下载吧,价低环保! 内容要点: ...
- Python成长之路【第九篇】:Python基础之面向对象
一.三大编程范式 正本清源一:有人说,函数式编程就是用函数编程–>错误1 编程范式即编程的方法论,标识一种编程风格 大家学习了基本的Python语法后,大家就可以写Python代码了,然后每个人 ...
- (转)Python成长之路【第九篇】:Python基础之面向对象
一.三大编程范式 正本清源一:有人说,函数式编程就是用函数编程-->错误1 编程范式即编程的方法论,标识一种编程风格 大家学习了基本的Python语法后,大家就可以写Python代码了,然后每个 ...
- 第九篇:强化学习Q-learning算法 通俗介绍
你好,我是郭震(zhenguo) 今天介绍强化学习第九篇:Q-learning算法 前面我们介绍强化学习基本概念,马尔科夫决策过程,策略迭代和值迭代,这些组成强化学习的基础. 从今天开始逐步介绍常用强 ...
- Python学习第九篇:zipfile 库操作压缩包
Python学习第九篇:zipfile 库操作压缩包 -- 活动地址:CSDN21天学习挑战赛 zipfile是python里用来做zip格式编码的压缩和解压缩的 zipfile里有两个非常常用的 ...
- Noah Mt4跟单系统制作第九篇 Mt4TradeApi历史报价篇
Noah Mt4跟单系统制作第九篇 Mt4TradeApi历史报价篇 using System; using System.Collections.Generic; using System.Linq ...
最新文章
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))) TNS-12541: TNS:no li
- CSS实现 全屏 遮罩
- win10 Linux子系统 交叉编译器注意事项
- 为rm添加一个回收站|将linux下的rm命令改造成mv到指定的目录下
- linux c 遍历目录 及 目录下文件
- js动态给当前点击元素添加css类
- 局域网通过专线上网的维护经验点滴
- 求最大连续子序列和——解法1 – 暴力出奇迹||解法2 – 分治
- 1.4 isAlive()方法
- 计算机与应用化学怎么投稿,计算机与应用化学杂志
- 【汇编语言】8086、x86-32和C语言【赋值语句 和 数组】的对比学习(王爽学习笔记:5.8段前缀的使用)
- 计算机网络中常见拓扑结构及特点,常见的网络拓扑结构有哪些?并说明其优缺点....
- 做数仓运维,你必须要认识这个眼观六路耳听八方的“能人”
- element upload预览_vue2.0 使用element-ui里的upload组件实现图片预览效果方法
- Mongo 与 SQL 操作对应介绍
- 关于Microsoft Office 2007 Beta 简体中文版的一些消息
- c语言串口控制单片机,利用USART实现单片机与串口通信[C语言]
- 数据库MySQL学习心得
- TypeError: ufunc ‘true_divide‘ output (typecode ‘d‘) could not be coerced to provided outp
- git报错:remote: warning: Large files detected. / 移动文件夹