how to make UITextView height dynamic according to text length?

前端 未结 21 2385
隐瞒了意图╮
隐瞒了意图╮ 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

    its working

    func textViewDidChange(_ textView: UITextView) {
        let fixedWidth = textviewconclusion.frame.size.width
        textviewconclusion.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
        let newSize = textviewconclusion.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
        var newFrame = textviewconclusion.frame
        newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
        textviewconclusion.frame = newFrame
    }
    

提交回复
热议问题