UITextView issue in iOS 8: text view not scrolling when typing

I faced the problem in iOS 8 in the previous version, works great.

My text view is about 4 lines long, when I typing more than 4 lines of text, it automatically scrolls, but in this case it does not scroll in iOS8.

Here is my code.

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    NSString *updatedString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    textView.text = updatedString;
    return NO;


}

      

Thanks in advance.

+3


source to share


2 answers


Try this code.



- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    NSString *updatedString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    //textView.text = updatedString;
    [textView replaceRange:textView.selectedTextRange withText:text];
    return NO;

}

      

+5


source


To edit the text of the UITextView, you need to update it in the textStorage field:

[_textView.textStorage beginEditing];

NSRange replace = NSMakeRange(10, 2); //enter your editing range
[_textView.textStorage replaceCharactersInRange:replace withString:@"ha ha$ "];

//if you want to edit the attributes
NSRange attributeRange = NSMakeRange(10, 5); //enter your editing attribute range
[_textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:attributeRange];

[_textView.textStorage endEditing];

      



Good luck.

0


source







All Articles