IOS之简单代理
来源:互联网 发布:gameloft足球java 编辑:程序博客网 时间:2024/05/20 03:38
#import "AppDelegate.h"
//要使用输入框的代理方法
//1.导入代理文字
//2.挂上代理
//3.实现代理的方法
//导入代理的名字
@interface AppDelegate ()<UITextFieldDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*
UITextField :->UIControl的子类->UIView的子类
enable tag background color
文本输入框
text:可以获得或者改变 输入框的文字内容
placeholder:提示文字
textColor:文字颜色
fon:文字大小
textAlignment:对齐方式
adjustFontSizeToFitWidth:让文字根据宽度适配
minimumFontSize:设置文字的最小字号
delegate:代理
clearButtonMode:设置清楚按钮什么时候显示
UITextFieldViewModeNever,永远不显示
UITextFieldViewModeWhileEditing,当编辑的时候显示
UITextFieldViewModeUnlessEditing,不再编辑的时候显示
UITextFieldViewModeAlways 永远显示
leftView:左侧视图->输入框左侧视图
rightView:左侧视图->输入框左侧视图
并不是设置了左侧右侧视图 就可以显示出来需要配合使用下面属性
leftViewMode:设置什么情况下显示左侧视图
rightViewMode:设置什么情况下显示右侧视图
imputView: 键盘上面的视图
imputAccessoryview:键盘区域的视图
输入框的方法(代理方法)
开始编辑的时候调用
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
结束编辑的时候调用
- (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
点击清除按钮的时候调用
- (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.
专为输入框准备的响应事件
UIControlEventEditingDidBegin = 1 << 16, // UITextField
UIControlEventEditingChanged = 1 << 17,
UIControlEventEditingDidEnd = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing
borderstyle:输入框的样式
UITextBorderStyleNone, 没有样式
UITextBorderStyleLine, 黑线边框
UITextBorderStyleBezel,黑线阴影
UITextBorderStyleRoundedRect 圆角
*/
/*
注意点:
1、如果想使用代理方法必须先导入代理
2、如果代理方法没有触发 看是否挂上了代理
在使用左右侧视图的时候要配合左右视图的model来使用
*/
/*
keyboardType:键盘的样式
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
✮✮✮✮✮数字符号
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, 邮箱地址类型 // A type optimized for multiple email address entry (shows space @ . prominently).
UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1), // A number pad with a decimal point.
UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0), // A type optimized for twitter text entry (easy access to @ #)
UIKeyboardTypeWebSearch NS_ENUM_AVAILABLE_IOS(7_0),网页搜索 // A default keyboard type with URL-oriented addition (shows space . prominently).
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
*/
[self.windowmakeKeyAndVisible];
UITextField *accTextField=[[UITextFieldalloc]initWithFrame:CGRectMake(10,40, [UIScreenmainScreen].bounds.size.width-20,40)];
accTextField.backgroundColor=[UIColorredColor];
accTextField.borderStyle=UITextBorderStyleRoundedRect;
//提示文字
accTextField.placeholder=@"请输入账号";
//清除按钮
accTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
UIImageView *leftImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 40, 40)];
leftImageView.image=[UIImageimageNamed:@"1.jpg"];
accTextField.leftView=leftImageView;
accTextField.leftViewMode=UITextFieldViewModeUnlessEditing;
UIView *inputV=[[UIViewalloc]initWithFrame:CGRectMake(0,0, CGRectGetWidth([UIScreenmainScreen].bounds),40)];
inputV.backgroundColor=[UIColorlightGrayColor];
// accTextField.inputView=inputV;
// accTextField.inputAccessoryView=inputV;
//想使用代理方法必须挂上代理
accTextField.delegate=self;
accTextField.tag=101;
[self.windowaddSubview:accTextField];
return YES;
}
- IOS之简单代理
- ios之代理
- iOS 简单代理(delegate)实现
- iOS 简单代理(delegate)实现
- iOS 简单代理(delegate)实现
- iOS 简单代理(delegate)实现
- iOS 简单代理(delegate)实现
- iOS 简单代理(delegate)实现
- 代理模式之简单的动态代理
- iOS开发之代理模式
- iOS之代理delegate使用
- iOS 之 代理五步骤
- IOS 笔记之 网络代理
- iOS之代理设计模式
- iOS传值之代理
- iOS开发之代理协议
- iOS开发模式之代理
- iOS 探讨之 代理模式
- 序列终结者
- 【计算机网络】:可靠数据传输的原理
- Android Log等级的介绍
- 通过图和文字说明来辨别mysql和Oracle数据库
- 黑马程序员—java基础复习—基础知识
- IOS之简单代理
- FJNU OJ 1053
- Python字典里面创建字典
- 数值的整数次方
- Git详解之二:Git基础[转]
- LeetCode(95) Unique Binary Search Trees II解题报告
- 判断字符是否为汉字【转】
- IDEA部署Spark1.5.2开发环境--Spark学习(基础)
- HDU-3555-Bomb【数位dp】