Scroll UITextView To Bottom

后端 未结 10 1698
误落风尘
误落风尘 2020-12-08 07:26

I am making a an app that has a UITextView and a button.

When I click the button some text will add in the UITextView.

But when c

10条回答
  •  鱼传尺愫
    2020-12-08 08:00

    You have to implement a delegate method. The code below checks whether a newline has been entered and, if so, scrolls to the bottom of the textView:

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
    
        if ([text isEqualToString:@"\n"]) {
            textView.contentOffset = CGPointMake(0.0, textView.contentSize.height);
        }
        return YES;
    }
    

提交回复
热议问题