To add placeholder UITextView first take outlet of UITextField
ex- @property (weak, nonatomic) IBOutlet UITextView *yourTextView;
Then follow these steps
1. In viewDidLoad add these line of code
self.yourTextView.text = @Please type here.;
self.yourTextView.textColor = [UIColor lightGrayColor];
self.yourTextView.delegate = self;
2. Place this code inside delegate method of UITextViewDelegate
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
self.yourTextView.text = @; //remove placeholder text as user start typing.
self.yourTextView.textColor = [UIColor grayColor];
return YES;
}
-(void) textViewDidChange:(UITextView *)textView
{
if(self.yourTextView.text.length == 0)
{
self.yourTextView.textColor = [UIColor lightGrayColor];
self.yourTextView.text = @Please type here.; //put placeholder text if user hasnt type any character.
[self.yourTextView resignFirstResponder];
}
}
0 Comment(s)