UITextField border color

后端 未结 9 1471
一生所求
一生所求 2020-11-28 02:43

I have really great wish to set my own color to UITextField border. But so far I could find out how to change the border line style only.

I\'ve used background prope

9条回答
  •  一生所求
    2020-11-28 03:26

    Import QuartzCore framework in you class:

    #import 
    

    and for changing the border color use the following code snippet (I'm setting it to redColor),

        textField.layer.cornerRadius=8.0f;
        textField.layer.masksToBounds=YES;
        textField.layer.borderColor=[[UIColor redColor]CGColor];
        textField.layer.borderWidth= 1.0f;
    

    For reverting back to the original layout just set border color to clear color,

        serverField.layer.borderColor=[[UIColor clearColor]CGColor];
    

    in swift code

        textField.layer.borderWidth = 1
        textField.layer.borderColor = UIColor.whiteColor().CGColor
    

提交回复
热议问题