Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add placeholder inside UITextView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 183
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: