0

I am trying to create a text field in objective-c with a big corner radius, like the searchField in iOS. In my xib i have added a UITextField. I style the textfield in objective-C like this:

// corner radius
textField.layer.cornerRadius = 20.0f;
textField.layer.masksToBounds = YES;
textField.backgroundColor = [UIColor clearColor];

[textField setFont:[UIFont fontWithName:@"Univers-Condensed-Medium" size:18.0]];

Result: The corners of the input are not visible, some white background overlays these. You can see the problem in this image:

Screenshot of the problem

I have tried several things like:

textField.leftView.opaque = NO;
textField.leftView.backgroundColor = [UIColor clearColor];

textField.inputView.opaque = NO;
textField.inputView.backgroundColor = [UIColor clearColor];

textField.rightView.opaque = NO;
textField.rightView.backgroundColor = [UIColor clearColor];

I even added an icon (just for testing) all gave the same result. What do I need to do to make the corners visible?

1 Answer 1

2

I had done some test and no white background overlaps, it is just this way the textfield look like when you change the corner radius. Try to change the background color of the UIView that the textfield is inside, and see that it will be always this way.

Unfortunately, if you want to change the cornerRadius and want it to be displayed in the way you posted here, maybe you need to use some background image, I do not know.

If I was you I will use the textField without the cornerRadius.

Sign up to request clarification or add additional context in comments.

3 Comments

OK, I see what you mean. I do see some threads on internet where people got it working, anything else I am doing wrong why the textbox is appearing like this?
You can set a border something like [textField.layer setBorderWidth: 1.0]; its dependes what do you want, what I am saying is that the textfield is getting the expected behavior for what code you show here. If you show me exactly what you want maybe I can help you more.
I want to have a textfield that looks exactly like the search bar field. So what I was trying to do was to give the textfield with a UITextBorderStyleBezel a cornerradius. I guess Apple uses images for the UITextBorderStyleBezel, so when you apply a corner radius, it will not show the corners of the image.. I have now solved it by using a custom background image for the textfield.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.