views:

1128

answers:

2

Is there an obvious way to make a text input box that has rounded edges?

I'm not talking about setting a UITextField's borderStyle to UITextBorderStyleRoundedRect. That only gives me rounded corners.

I'm talking about the style text field used as input in the SMS app (before you hit send), or the UISearchBar. I've also seen it used in 3rd party applications (for example, the comment input box in the Facebook application).

Is this possible using standard Cocoa Touch? Or do I have to bring my own background images to the table?

+1  A: 

I think that the easiest way of doing this is to use a custom background. Here is a complete API overview of the UITextField class.

Jack
+4  A: 

You can also set the corner radius on the textField, which might give you enough control to get the look you want:

textField.layer.cornerRadius = 10;

Be sure to include #import <QuartzCore/QuartzCore.h> to access this.

(the above answer it probably a better answer; this just might be easier)

justin
This is so good. But I could only change the corner of not UITextField but UITextView. Is it applicable to UITextField?
KatokichiSoft
Yes, it works on everything derived from UIView. When you say you couldn't get it to work, what do you mean? It doesn't compile, or it has no visible effect? If the second, are you setting the borderStyle on the UITextField? That managed to override it when I did it.
justin
I have found this to be highly computational with 15 large textfields all in cells, each with rounded corners, whilst scrolling continually.
norskben