Scroll UITextView To Bottom

后端 未结 10 1675
误落风尘
误落风尘 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 07:46

    You can use the following code if you are talking about UITextView:

    -(void)scrollTextViewToBottom:(UITextView *)textView {
         if(textView.text.length > 0 ) {
            NSRange bottom = NSMakeRange(textView.text.length -1, 1);
            [textView scrollRangeToVisible:bottom];
         }
    
    }
    

    SWIFT 4:

    func scrollTextViewToBottom(textView: UITextView) {
        if textView.text.count > 0 {
            let location = textView.text.count - 1
            let bottom = NSMakeRange(location, 1)
            textView.scrollRangeToVisible(bottom)
        }
    }
    

提交回复
热议问题