开发者

how to do this operation in UITextView (iphone)

In My textView there is a default value of "First name "

I want to implement such operation in it..

1) it should be shown "first name" firstly

2) when I start editing it should became nil

3)when I am complete with my editing if the field is still nil then it should be shown as "first name" again

can anyone help me with this?

//*This is now what I am doing now**//

 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
    replacementText:(NSString *)text
         {    
if (first_name.text=@"") {
    first_name.text=@"First Name(Required)";
    }
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:@"\n"]) {
    // Be sure to test for equality using the "isEqualToString" message

    [textView resignFirstR开发者_运维技巧esponder];

    // Return FALSE so that the final '\n' character doesn't get added
    return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
   return TRUE;
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
NSLog(@"textViewShouldBeginEditing");
textView.scrollEnabled=NO;

if (textView == first_name) {
    first_name.text=nil;
}


return YES;

}


All the delegate methods you can use to implement this concept can be found in the UITextViewDelegate Protocol Reference.


You need to overlay a UILabel on top of the text view with the text you want, set its userInteractionEnabled to NO and on the text field delegate method shouldBeginEditing you hide the UILabel before returning YES and unhide it on shouldFinishEditing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜