tags:

views:

72

answers:

3

Hi, How can add a clearbutton (cross inside a circle) for text view like in text field?

A: 

Do you mean UITextField? Use the "Clear Button" drop down in the Attributes Inspector of the Interface Builder

If you want to do this in code you will have to use

textfield.clearButtonMode = UITextFieldViewModeWhileEditing (or any of the mode from here)

Mihir Mathuria
I was looking for text view and not text field.
Abhinav
-1 Read the question carefully, OP said clearly he wants to duplicate `UITextField`'s clear button for use with a `UITextView`.
BoltClock
+1  A: 

There's nothing built in like there is for the UITextField. You'd have to add the view yourself (probably a UIButton) and place it correctly and also somehow get the text to wrap around it correctly. (And I don't think the latter is really possible.)

Maybe instead you should display a toolbar above the keyboard (or an inputAccessoryView if you're targeting 3.2 and later) that provides a clear button.

Robot K
A: 

just make a uibutton and put it on uitextview and set its action for clear text view;

uitextview.frame = (0,0,320,416);

uibutton.frame = (310,0,10,10);
[uibutton setimage:@"cross.png" forcontrolstate:uicontrolstatenoraml];
[uibutton addTarget:self action:@selector(clearButtonSelected:) forControlEvents:UIControlEventTouchUpInside];

-(void)clearButtonSelected{
    uitextview=@"";
}

hope you want to clear the text view text when you click on cross button above is help if not understand then i can send you proper program for that

GhostRider
perfect. Thanks.
Abhinav