views:

700

answers:

2

I can't understand this. Basically, I want the same style as a UITextField, but to be able to take a multiline string. I'm sure it's a frequently asked problem, but I can't find a readable solution anywhere on the web.

Oh, and how can I make the damn keyboard go away when I touch out of it, or press a "Done" button (which doesn't seem to exist)?

A: 

For textview unfortunatl u cannot change it's shape, what u can do however is make a rounded square image put that behind a text view and make the textviews background transparent, it looks good like that. To dismiss the keyboard u need to have a button pop up whenever the user starts ediing and have them press it to dismiss the keyboard

Daniel
A: 

There's no builtin way to change the appearance of a UITextField. What you can do instead is either subclass UITextField to change its appearance or add some kind of background view to it, so it appears to have the shape you want. (I'm assuming you want a fixed-height field; if you want the field to change height, like in Apple's SMS application, you're going to have to mess around with watching changes in the field's frame and adjust your background view appropriately.)

To get rid of the keyboard, send the object that's being edited (the "first responder" in Cocoa parlance) the resignFirstResponder method:

[myTextField resignFirstResponder];

This causes the field to give up its status as the object that handles input like text, touches, etc., and will make the keyboard disappear. Nest this inside a method that gets called when your Done button is pressed and you're set. You can also override touchesEnded:withEvent: in your view controller if you want any press outside the field to resign the first responder on the text field:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];

    [myTextField resignFirstResponder];
}
Tim
Just to add to this a bit, the usual pattern with UITextViews and editing is to place some kind of "Done" button up on the nav bar when the keyboard is presented - that's because the user is allowed to use a return key in a text field.
Kendall Helmstetter Gelner