UITextField Set Border

2019-08-22 21:52发布

问题:

I want to make my login interface a little bit more fancy. So I wanted to build somethin like this:

Thats what i Have to far:

    self.usernameTextField.layer.borderWidth = 1.0f;
self.usernameTextField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor];
self.usernameTextField.layer.cornerRadius = 5;
self.usernameTextField.clipsToBounds      = YES;

    self.passwordTextField.layer.borderWidth = 2.0f;
self.passwordTextField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor];
self.passwordTextField.layer.cornerRadius = 5;
self.passwordTextField.clipsToBounds      = YES;

How can I connect them? There is still a gap between the two UITextFields..

回答1:

Put plain image background like your interface and put two text fields on that image and set boarder style like below.

[yourTextField setBorderStyle:UITextBorderStyleNone];


回答2:

The example you show is almost certainly using a table view. If you want to mimic it created a grouped table view with 2 static rows and add your text fields to each row. Make sure the text fields border style is set to none (it should be the default in IB), then set your placeholder text and color. If you want the icons, that is probably just a small UIImageView to the left of the text field.



回答3:

You can set your UITextField border style to none.

[self.textField setBorderStyle:UITextBorderStyleNone];

and then use custom background images, to get the desired look.



回答4:

Create your both TextField custom type. Dont set any border style.. Fix the image in ImageView and then place the two text field frame for the text in imageview.