Search code examples
iosuitextfieldios7formborderstyle

UITextfield borderColor and width on one side of the text field


I have a text field setup like so:

textField.borderStyle = UITextBorderStyleLine;
textField.layer.borderColor = [[UIColor greenColor] CGColor];
textField.layer.borderWidth= 10.0f;'

But is it possible to just have a larger border on the left side and it be a different color? Or do I have to position a drawRect there with the color I want and position?


Solution

  • try with this code might be help's you add Border left side of custom TextFiled like Bellow:-

    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
        UIView *bottomBorder = [[UIView alloc]
                                initWithFrame:CGRectMake(0,0,4,txtField.frame.size.height)];
        bottomBorder.backgroundColor = [UIColor redColor];
        [txtField addSubview:bottomBorder];
    
    }
    

    This Bellow delegate Code for start after some space in textfield

    - (void)textFieldDidBeginEditing:(UITextField *)textField {
        UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
        textField.leftView = paddingView;
        textField.leftViewMode = UITextFieldViewModeAlways;
    }
    

    OUTPUT look like this:-

    enter image description here