Scroll UITextView To Bottom

后端 未结 10 1704
误落风尘
误落风尘 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:49

    The Swift version of @Hong Duan answer

    func scrollTextViewToBottom(textView: UITextView) {
        if textView.text.count > 0 {
            let location = textView.text.count - 1
            let bottom = NSMakeRange(location, 1)
            textView.scrollRangeToVisible(bottom)
    
            // an iOS bug, see https://stackoverflow.com/a/20989956/971070
            textView.isScrollEnabled = false
            textView.isScrollEnabled = true
        }
    }
    

提交回复
热议问题