Textfield单行文本输入框

作者: aaa000 | 来源:发表于2016-05-31 15:34 被阅读601次
    //透明度的的设定
        self.textfield.alpha = 1;
        
        //设定是否隐藏
        self.textfield.hidden = NO;
        
        //背景的设置
        self.textfield.backgroundColor = [UIColor clearColor];
        
        //设置文本信息
        self.textfield.text = @"123";
        
        //设置文本的字体的颜色
        self.textfield.textColor = [UIColor purpleColor];
        
        //设置文本对其方式
        self.textfield.textAlignment = NSTextAlignmentLeft;
        
        //设置文本边框的样式
        self.textfield.borderStyle = UITextBorderStyleRoundedRect;
        
        //设置提示输入信息
        self.textfield.placeholder = @"请输入。。。。。";
        
        //设置再次成为第一响应者的时候是否清空当前内容
        self.textfield.clearsOnBeginEditing = YES;
        
        //设置右侧的clear Button 什么时候显示
        self.textfield.clearButtonMode = UITextFieldViewModeAlways;
        
        
        UIView *vi = [self create_A_View];
        //设置左视图
        self.textfield.leftView = vi;
        
        //设置return 键上显示的文字
        self.textfield.returnKeyType = UIReturnKeyDone;
        
        //设置弹出键盘的样式
        self.textfield.keyboardType = UIKeyboardTypeNumberPad;
        
        //设置输入的文本是否加密
        self.textfield.secureTextEntry = NO;
        
        //设置边框的颜色
        self.textfield.layer.borderColor = [UIColor redColor].CGColor;
        
        //设置 是否提示大小写
        self.textfield.autocapitalizationType = UITextAutocorrectionTypeNo;
        
        //设置字体的大小
        self.textfield.font = [UIFont systemFontOfSize:14];
    
    代理方法
    #pragma mark - 是否可以开始编辑
    -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        return YES;
    }
    #pragma mark - textFieldDidBeginEditing
    -(void)textFieldDidBeginEditing:(UITextField *)textField
    {
        NSLog(@"textFieldDidBeginEditing");
    }
    #pragma mark - 是否可以点击键盘的ruturn按钮
    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        return YES;
    }
    #pragma mark -  是否可以结束编辑
    -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
    {
        return YES;
    }
    #pragma mark - 点击右侧的清楚按钮是否有效
    -(BOOL)textFieldShouldClear:(UITextField *)textField
    {
        return YES;
    }
    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        if (textField.text.length > 10 && string.length > 0)
        {
            return NO;
        }
        return YES;
    }
    
    
    target - action 文本框中内容发生改变的时候触发
    [_textfield addTarget:self action:@selector(edtingChanged:) forControlEvents:UIControlEventEditingChanged];
    -(void)edtingChanged:(UITextField *)sender
    {
        NSLog(@"*****  %@  *****",sender.text);
    }
    

    相关文章

      网友评论

        本文标题:Textfield单行文本输入框

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