在登錄界面中担猛,UITextFiled左邊添加圖片
//設(shè)置左邊添加的圖片
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_user"]];
userImage.frame = CGRectMake(0, 0, CGRectGetHeight(self.userName.frame), CGRectGetHeight(self.userName.frame);
userImage.contentMode = UIViewContentViewModeCenter;
//圖片添加到self.userName的左邊
self.userName.leftView = userImage;
self.userName.leftViewMode = UITextFiledViewModeAlways;
動(dòng)態(tài)監(jiān)聽UITextFiled的text變化
- 當(dāng)動(dòng)態(tài)監(jiān)聽UITextFiled的text變化時(shí)蒂培,可以使用本地通知事件或add Target來監(jiān)聽
- 通過本地通知
// 開始編輯
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEditing) name:UITextFieldTextDidBeginEditingNotification object:self];
// 編輯中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editing) name:UITextFieldTextDidEndEditingNotification object:self];
// 結(jié)束編輯
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditing) name:UITextFieldTextDidChangeNotification object:self];
- 通過addTarget:因UITextFiled繼承UIControl,可以通過addTarget來監(jiān)聽文本框的變化
// 開始編輯
[self.textFiled addTarget:self action:@selector(beginEditing) forControlEvents:UIControlEventEditingDidBegin];
// 編輯中
[self.textFiled addTarget:self action:@selector(editing) forControlEvents:UIControlEventEditingChanged];
// 結(jié)束編輯
[self.textFiled addTarget:self action:@selector(endEditing) forControlEvents:UIControlEventEditingDidEnd];
// 'return key' ending editing
[self.textFiled addTarget:self action:@selector(endOnExit) forControlEvents:UIControlEventEditingDidEndOnExit];
友情資料:iOS_成才錄