美文网首页
UITextField

UITextField

作者: Smicro | 来源:发表于2016-06-07 17:30 被阅读28次

    [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;

    }

    链接:相关链接

    相关文章

      网友评论

          本文标题:UITextField

          本文链接:https://www.haomeiwen.com/subject/vfnddttx.html