UITextField

[textField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型  

textField.placeholder = @"password"; //默认显示的字  

textField.secureTextEntry = YES; //密码  

textField.autocorrectionType = UITextAutocorrectionTypeNo;  //自动校正

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;  //自动大写输入

textField.returnKeyType = UIReturnKeyDone;  

textField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X  

UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]]; 

text.rightView=imgv;

text.rightViewMode = UITextFieldViewModeAlways;    如果是在最左侧加图片就换成:text.leftView=imgv;

text.leftViewMode = UITextFieldViewModeAlways;

textField.delegate = self;

Methods:

- (BOOL)textFieldShouldReturn:(UITextField *)textField  { //这个代理方法在点击键盘return时调用    

 [self.textField resignFirstResponder];  //关闭键盘   

 return YES;  

 } 

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {//这个方法虽然只会在textField的内容已经变化后才调用,但是也给出了即将变化的range和string。根据这两个参数我们就可以做到实时监听text的变化了

NSString *str = [textField.text stringByReplacingCharactersInRange:range withString:string];//当前textField的text

for (int i = 0; i < _searchHistoryRecordsArr.count; i++) {

if ([_searchHistoryRecordsArr[i] hasPrefix:str]) {

[_searchHistoryRecordsArr exchangeObjectAtIndex:i withObjectAtIndex:_searchHistoryRecordsArr.count - 1];

[_showResultListTableView reloadData];

}

}

return YES;

}


链接:相关链接

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容