<p style="margin-top: 0px; margin-bottom: 0px;"><span style="white-space: pre; background-color: rgb(240, 240, 240);"><span style="font-family:Microsoft YaHei;font-size:24px;">一、属性及方法</span></span><span style="font-family:Menlo;font-size: 20px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px;"><span style="white-space: pre; background-color: rgb(240, 240, 240);"><span style="font-family:Microsoft YaHei;font-size:24px;">
</span></span></p><p style="margin-top: 0px; margin-bottom: 0px;"><span style="white-space: pre; background-color: rgb(240, 240, 240);"><span style="font-family:Microsoft YaHei;font-size:24px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 边框样式</span>
</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(195, 34, 117);">typedef</span> <span style="color: rgb(195, 34, 117);">NS_ENUM</span>(NSInteger, UITextBorderStyle) </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextBorderStyleNone,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 无边框</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextBorderStyleLine,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 直线边框</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextBorderStyleBezel,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 带内阴影边框</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextBorderStyleRoundedRect<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 带圆角边框</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">};</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 控件辅助UI(clearButton、leftView</span></span><span style="color: rgb(29, 148, 33);font-size:18px;">)的显示模式</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(195, 34, 117);">typedef</span> <span style="color: #c32275">NS_ENUM</span>(NSInteger, UITextFieldViewMode)</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> {</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextFieldViewModeNever,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 从不出现</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextFieldViewModeWhileEditing,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 编辑时出现</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextFieldViewModeUnlessEditing,<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 除了编辑外都出现</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"> UITextFieldViewModeAlways<span style="white-space:pre"> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 一直出现</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">};</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(97, 34, 174);"><span style="font-size:18px;"><span style="color: #78492a">NS_CLASS_AVAILABLE_IOS</span><span style="color: #000000">(</span><span style="color: #0435ff">2</span><span style="color: #000000">_0) </span><span style="color: #c32275">@interface</span><span style="color: #000000"> UITextField : </span>UIControl<span style="color: #000000"> <</span>UITextInput<span style="color: #000000">, </span>NSCoding<span style="color: #000000">> </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">copy</span>) <span style="color: #6122ae">NSString</span> *text; <span style="color: #1d9421"> </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">copy</span>) <span style="color: #6122ae">NSAttributedString</span> *attributedText; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">retain</span>) <span style="color: #6122ae">UIColor</span> *textColor; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">retain</span>) <span style="color: #6122ae">UIFont</span> *font; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>) <span style="color: #703daa">NSTextAlignment</span> textAlignment; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 设置边框样式,只有设置了才会显示边框样式。如果边框样式设置为 <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">UITextBorderStyleRoundedRect </span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"></span> <span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">自定义的背景图片将被忽略。</span> </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #703daa">UITextBorderStyle</span><span style="color: #000000"> borderStyle; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">,</span><span style="color: #c32275">copy</span><span style="color: #000000">) </span><span style="color: #6122ae">NSDictionary</span><span style="color: #000000"> *defaultTextAttributes </span><span style="color: #78492a">NS_AVAILABLE_IOS</span><span style="color: #000000">(</span><span style="color: #0435ff">7</span><span style="color: #000000">_0); </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 占位字符</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">copy</span>) <span style="color: #6122ae">NSString</span> *placeholder; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">copy</span>) <span style="color: #6122ae">NSAttributedString</span> *attributedPlaceholder <span style="color: #78492a">NS_AVAILABLE_IOS</span>(<span style="color: #0435ff">6</span>_0); </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 重新编辑时是否清除旧文本内容</span>
</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #c32275">BOOL</span><span style="color: #000000"> clearsOnBeginEditing; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; color: rgb(29, 148, 33);"><span style="font-family:FangSong_GB2312;font-size:18px;"><span style="color: rgb(0, 0, 0);"></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; color: rgb(29, 148, 33);"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">//</span> 设置文字大小是否自动缩小以适应文本窗口大小。默认保持原来大小而让长文本滚动。</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #c32275">BOOL</span><span style="color: #000000"> adjustsFontSizeToFitWidth;</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #000000"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 设置自动缩小的最小字体。需设置 <span style="font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">adjustsFontSizeToFitWidth 为YES,此属性才有效。</span></span> </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #703daa">CGFloat</span><span style="color: #000000"> minimumFontSize; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">,</span><span style="color: #c32275">assign</span><span style="color: #000000">) </span><span style="color: #c32275">id</span><span style="color: #000000"><</span><span style="color: #6122ae">UITextFieldDelegate</span><span style="color: #000000">> delegate; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #000000"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 设置背景图片,只有 <span style="font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">borderStyle 为 <span style="font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">UITextBorderStyleNone 时才有效。</span></span></span> </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">,</span><span style="color: #c32275">retain</span><span style="color: #000000">) </span><span style="color: #6122ae">UIImage</span><span style="color: #000000"> *background;</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #000000"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 设置控件不可用时的背景图片</span> </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">,</span><span style="color: #c32275">retain</span><span style="color: #000000">) </span><span style="color: #6122ae">UIImage</span><span style="color: #000000"> *disabledBackground; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(195, 34, 117);"><span style="font-size:18px;">@property<span style="color: #000000">(</span>nonatomic<span style="color: #000000">,</span>readonly<span style="color: #000000">,</span>getter<span style="color: #000000">=isEditing) </span>BOOL<span style="color: #000000"> editing;</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #c32275">BOOL</span><span style="color: #000000"> allowsEditingTextAttributes </span><span style="color: #78492a">NS_AVAILABLE_IOS</span><span style="color: #000000">(</span><span style="color: #0435ff">6</span><span style="color: #000000">_0); </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">,</span><span style="color: #c32275">copy</span><span style="color: #000000">) </span><span style="color: #6122ae">NSDictionary</span><span style="color: #000000"> *typingAttributes </span><span style="color: #78492a">NS_AVAILABLE_IOS</span><span style="color: #000000">(</span><span style="color: #0435ff">6</span><span style="color: #000000">_0); </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 设置清除按钮出现的模式</span>
</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #703daa">UITextFieldViewMode</span><span style="color: #000000"> clearButtonMode; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">retain</span>) <span style="color: #6122ae">UIView</span> *leftView; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #703daa">UITextFieldViewMode</span><span style="color: #000000"> leftViewMode; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// rightView 与 clearButton 同时出现时后者会被遮盖</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: #c32275">@property</span>(<span style="color: #c32275">nonatomic</span>,<span style="color: #c32275">retain</span>) <span style="color: #6122ae">UIView</span> *rightView; </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-size:18px;"><span style="color: #c32275">@property</span><span style="color: #000000">(</span><span style="color: #c32275">nonatomic</span><span style="color: #000000">) </span><span style="color: #703daa">UITextFieldViewMode</span><span style="color: #000000"> rightViewMode; </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo; white-space: pre; background-color: rgb(240, 240, 240);">/<span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/</span> </span><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';">界面重写绘制行为 </span></span></p><p style="margin-top: 0px; margin-bottom: 0px; min-height: 24px;"><span style="color: rgb(29, 148, 33);font-size:18px;"><span style="font-family:Heiti SC Light;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/<span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/ </span></span></span></span><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';">除了</span><span style="color: rgb(29, 148, 33); font-family: Menlo;">UITextField</span><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';">对象的风格选项,你还可以定制化</span><span style="color: rgb(29, 148, 33); font-family: Menlo;">UITextField</span><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';">对象,为他添加许多不同的重写<span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">方法,来改</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"> 变文本字段的显示行为<span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">。这些方法都会返回一个</span><span style="color: rgb(29, 148, 33);font-size:18px; white-space: pre; background-color: rgb(240, 240, 240); font-family: Menlo;">CGRect</span><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">结构,制定了文本字段每个部件的边界范围。以下方法都</span></span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"> 可以重写</span></span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">
</span></span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(29, 148, 33); font-family: 'Heiti SC Light';font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 重写来重置边缘区域</span>
</span></span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)borderRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/</span><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/ 重写来重置文字区域</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)textRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 重写来重置占位符区域</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)placeholderRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 重写来重置编辑区域</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)editingRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">// 重写来重置clearButton位置,改变size可能导致button的图片失真</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)clearButtonRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)leftViewRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: #703daa">CGRect</span>)rightViewRectForBounds:(<span style="color: #703daa">CGRect</span>)bounds;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;">
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/</span><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/ 重写改变重绘文字属性。重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);"> super</span></span><span style="color: rgb(29, 148, 33);font-size:18px;">了。</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;">- (<span style="color: rgb(195, 34, 117);">void</span>)drawTextInRect:(<span style="color: #703daa">CGRect</span>)rect;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/</span><span style="color: rgb(29, 148, 33); font-family: Menlo;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">/ </span></span><span style="color: rgb(29, 148, 33); font-size: 18px;">重写改变绘制占位符属性。重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用</span><span style="font-size:18px;"><span style="color: rgb(29, 148, 33);"></span></span><pre name="code" class="objc"><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo; min-height: 24px;"><span style="font-size:18px;"><span style="color: rgb(29, 148, 33);"> super</span></span><span style="color: rgb(29, 148, 33);font-size:18px;">了。</span></p>
- (void)drawPlaceholderInRect:(CGRect)rect;
// 代替输入
// 代替标准的系统键盘
@property (readwrite, retain) UIView *inputView;
// 编辑时显示在系统键盘或用户自定义的inputView上面的视图
@property (readwrite, retain) UIView *inputAccessoryView;
@property(nonatomic) BOOL clearsOnInsertion NS_AVAILABLE_IOS(6_0);
@end
@interface UIView (UITextField)
- (BOOL)endEditing:(BOOL)force;
@end
@protocol UITextFieldDelegate <NSObject>
@optional
// 返回一个BOOL值,指定是否允许文本框开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
// 开始编辑时触发,文本框将成为 first responder
- (void)textFieldDidBeginEditing:(UITextField *)textField;
// 返回BOOL值,指定是否允许文本字段结束编辑,当编辑结束,文本字段会让出first responder
// 要想在用户结束编辑时阻止文本字段消失,可以返回NO, 文本字段不会让出first responder
// 这对一些文本字段必须始终保持活跃状态的程序很有用,比如即时消息
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
// 上面返回YES后执行;上面返回NO时有可能强制执行(e.g. view removed from window)
- (void)textFieldDidEndEditing:(UITextField *)textField;
// 当用户使用自动更正功能,把输入的文字修改为推荐的文字时,就会调用这个方法。
// 这对于想要加入撤销选项的应用程序特别有用
// 可以跟踪字段内所做的最后一次修改,也可以对所有编辑做日志记录,用作审计用途。
// 要防止文字被改变可以返回NO
// 这个方法的参数中有一个NSRange对象,指明了被改变文字的位置,建议修改的文本也在其中
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
// 返回一个BOOL值指明是否允许根据用户请求清除内容
// 可以设置在特定条件下才允许清除内容
- (BOOL)textFieldShouldClear:(UITextField *)textField;
// 返回一个BOOL值,指明是否允许在按下回车键时结束编辑
// 如果允许要调用 resignFirstResponder 方法,这会导致结束编辑,而键盘会被收起
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
@end
UIKIT_EXTERN NSString *const UITextFieldTextDidBeginEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidEndEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;