第九篇 - 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:]

时间: 2024-07-29 06:13:20

第九篇 - UITextField的相关文章

Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy

Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached基于一个存储键/值对的hashmap.其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信. Memc

第九篇 Integration Services:控制流任务错误

本篇文章是Integration Services系列的第九篇,详细内容请参考原文. 简介在前面三篇文章,我们创建了一个新的SSIS包,学习了脚本任务和优先约束,并检查包的MaxConcurrentExecutables属性.我们检查.演示并测试优先约束赋值为"成功"."完成"."失败"时对工作流的影响.我们学习了SSIS变量和表达式,并将它们应用到优先约束.这一篇,we introduce fault tolerance by examinin

第九篇 Replication:复制监视器

本篇文章是SQL Server Replication系列的第九篇,详细内容请参考原文. 复制监视器允许你查看复制配置组件的健康状况.这一篇假设你遵循前八篇,并且你已经有一个合并发布和事务发布.启动复制监控器复制监视器不是SSMS的一部分,它是一个独立的可执行文件(SqlMonitor.exe).在一个标准的SQL Server安装中开始菜单下找不到复制监视器.启动复制监视器的最简单方法是:SSMS对象资源管理器下连接到发布服务器,右击你的发布选择"启动复制监视器",如图9.1所示:图

用仿ActionScript的语法来编写html5——第九篇,仿URLLoader读取文件

第九篇,仿URLLoader读取文件 先看看最后的代码 function readFile(){ urlloader = new LURLLoader(); urlloader.addEventListener(LEvent.COMPLETE,readFileOk); urlloader.load("../file/test.txt","text"); } function readFileOk(){ mytxt.text = urlloader.data; } 基

Python之路【第九篇】:Python基础(26)——socket server

socketserver Python之路[第九篇]:Python基础(25)socket模块是单进程的,只能接受一个客户端的连接和请求,只有当该客户端断开的之后才能再接受来自其他客户端的连接和请求.当然我 们也可以通过python的多线程等模块自己写一个可以同时接收多个客户端连接和请求的socket.但是这完全没有必要,因为python标准库已经为 我们内置了一个多线程的socket模块socketserver,我们直接调用就可以了,完全没有必要重复造轮子. 我们只需简单改造一下之前的sock

第九篇 SQL Server代理了解作业和安全

本篇文章是SQL Server代理系列的第九篇,详细内容请参考原文 在这系列的前几篇,学习了如何在SQL Server代理作业步骤启动外部程序.你可以使用过时的ActiveX系统,运行批处理命令脚本,甚至自己的程序.你最好的选择是使用PowerShell的子系统运行PowerShell脚本.PowerShell脚本将允许你处理几乎所有方面的Windows和SQL Server问题.在这一篇,你会深入到SQL Server代理安全.安全是个令人困惑的话题,它值得一些明确的考虑.这系列有两个不同方面

学习java随笔第九篇:java异常处理

在java中的异常处理和c#中的异常处理是一样的都是用try-catch语句. 基本语法如下 try { //此处是可能出现异常的代码 } catch(Exception e) { //此处是如果发生异常的处理代码 } finally语句 try { //此处是可能出现异常的代码 } catch(Exception e) { //此处是如果发生异常的处理代码 } finally { //此处是肯定被执行的代码 } 抛出异常 使用thows和throw语句抛出异常 public static vo

SQL Server索引 - 索引(物化)视图 &lt;第九篇&gt;

一.索引视图基本概念 索引视图实际上是一种将一组唯一值“物化”为群集索引形式的视图,所为物化就是几乎和表一样,其数据也是会存储一份的(会占用硬盘空间,但是查询速度快,例如可以将count(),sum()等值设在索引视图中).其优点是它在提取视图背后的信息方面提供了一个非常快的查找方法.在第一个索引(必须是针对一组唯一值的聚集索引)之后,通过使用来自第一个索引的聚集键作为参考点,SQL Server还能在视图上建立额外的索引.其限制如下: 视图必须使用SCHEMABINDING选项: 如果视图引用

NHibernate Linq查询 扩展增强 (第九篇)

NHibernate Linq查询 扩展增强 (第九篇) 在上一篇的Linq to NHibernate的介绍当中,全部是namespace NHibernate命名空间中的IQueryOver<TRoot, TSubType>接口提供的.IQueryOver<TRoot, TSubType>这个借口实际上会被翻译成条件查询(Criteria Queries). 实际上Linq to NHibernate更加强大.我们先引入命名空间NHibernate.Linq,这里面有Linq

[老老实实学WCF] 第九篇 消息通信模式(上) 请求应答与单向

老老实实学WCF 第九篇 消息通信模式(上) 请求应答与单向 通过前两篇的学习,我们了解了服务模型的一些特性如会话和实例化,今天我们来进一步学习服务模型的另一个重要特性:消息通信模式. WCF的服务端与客户端在通信时有三种模式:单向模式.请求/应答模式和双工模式. 如果选用了单向模式,调用方在向被调用方进行了调用后不期待任何回应,被调用方在执行完调用后不给调用方任何反馈.如客户端通过单向模式调用了一个服务端的操作后,就去干别的了,不会等待服务端给他任何响应,他也无从得知调用是否成功,甚至连发生了