Tuesday, May 7, 2013

Multiline Text input or UItextView with Placeholder text

Hello All,

Hope all you awesome developers doing good and developing some cool projects, to let other people enjoy their lives (As being a developer, we Don`t have life ).

In one of my project, I got stuck to strange problem in which the requirement was such that I needed an Multiline inputfield having feature of placeholder text :( .

in iOS,
for multiline textInput we use - UITextView.
for textInput having placeholder feature - UITextfield.

Hope till now you might have got my problem. After 2 days of RnD(Googling ;)...), I got some links that helped me throughout.

I am hereby giving you the same coding which I used to implement the "Multiline text input with placeholder text property."

Hello, Now I am presenting the code snippet for u all, sorry for taking such long time.



#pragma mark - UItextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if( [text rangeOfCharacterFromSet:[NSCharacterSetnewlineCharacterSet]].location ==NSNotFound ) {
        return YES;
    }
    
    [textView resignFirstResponder];
    [scrollMessagescrollRectToVisible:CGRectMake(0, -110scrollMessage.frame.size.width,scrollMessage.frame.size.heightanimated:YES];
    returnNO;
}


- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
    if(textView.tag == 0) {
        [scrollMessagescrollRectToVisible:CGRectMake(0110scrollMessage.frame.size.width,scrollMessage.frame.size.heightanimated:YES];
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
        textView.tag = 1;
    }
    else {
        [scrollMessagescrollRectToVisible:CGRectMake(0110scrollMessage.frame.size.width,scrollMessage.frame.size.heightanimated:YES];
        textView.textColor = [UIColor blackColor];
    }
    returnYES;
}


Just give a couple of mins to understand this, and then just get ur answer!!!


Code will be available soon... :P

No comments:

Post a Comment