how to make UITextView height dynamic according to text length?

前端 未结 21 2318
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 05:44

As you can see in this image

the UITextView changes it\'s height according to the text length, I want to make it adjust it\'s height according to the te

21条回答
  •  难免孤独
    2020-11-28 05:51

    Swift 5, Use extension:

    extension UITextView {
        func adjustUITextViewHeight() {
            self.translatesAutoresizingMaskIntoConstraints = true
            self.sizeToFit()
            self.isScrollEnabled = false
        }
    }
    

    Usecase:

    textView.adjustUITextViewHeight()
    

    And don't care about the height of texeView in the storyboard (just use a constant at first)

提交回复
热议问题