Grodriguez
Grodriguez

Reputation: 21995

Remove border outline on text field when using UITextBorderStyle.RoundedRect

I am creating a text field with a semi-transparent background color (40% white) on which I am using UITextBorderStyle.RoundedRect for the rounded corners and text insets. This automatically sets a grey-ish border outline which I want to remove, but I can't find how.

I have tried the following:

I'm sure there must be an easy way to do this, but I can't find it.

Upvotes: 0

Views: 859

Answers (3)

Muhammad Zohaib Ehsan
Muhammad Zohaib Ehsan

Reputation: 931

If you set UITextBorderStyle.RoundedRect for the text field then the text field will add an image to the background of the text field with a grey border. That's why layer properties are not working becuase the border you are seeing is not on layer its an image added to text field.

You can verify it by debugging with the View Hierarchy. There will be an image added to the text field. The image will be created with the background color of the text field with a grey border and capInsets to avoid border stretch.

So your best bet is to set the text field to UITextBorderStyle.none. Then create border by yourself.

Upvotes: 1

Him bhatt
Him bhatt

Reputation: 49

If you want to just round the corners of textfield use

YourTextField.layer.cornerRadius = 8 //or any value you want to set

Upvotes: 0

51d4
51d4

Reputation: 21

I think the only way you can achieve this is by setting the border style to .none (and round the corners yourself). Then you can set the border style and colour the way you want it (or have no border at all).

Upvotes: 0

Related Questions