Thursday 14 March 2013

Create placeHolder In UITextView


- (void)viewDidLoad//create textview....
{

    tv.text = @"Write Your Comment Here";
    tv.textColor = [UIColor lightGrayColor];
    tv.delegate=self;
    tv.layer.borderColor=[[UIColor lightGrayColor] CGColor];
    tv.layer.borderWidth=5;
    tv.layer.cornerRadius=5;
.............

}
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
    if (tv.textColor == [UIColor lightGrayColor]) {
        tv.text = @"";
        tv.textColor = [UIColor blackColor];
    }
    
    return YES;
}
-(void) textViewDidChange:(UITextView *)textView
{
    if(tv.text.length == 0)
    {
        tv.textColor = [UIColor lightGrayColor];
        tv.text = @"Write Your Comment Here";
        [tv resignFirstResponder];
    }
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        if(tv.text.length == 0){
            tv.textColor = [UIColor lightGrayColor];
            tv.text = @"Write Your Comment Here";
            [tv resignFirstResponder];
        }
        return NO;
    }
    
    return YES;
}



No comments:

Post a Comment