UITextView动态改变高度
作者:
link_hui | 来源:发表于
2020-05-28 16:06 被阅读0次 func textViewDidChange(_ textView: UITextView) {
let textViewWidth = textView.frame.size.width
let content = textView.text
let contentSize = content?.size(font: UIFont.pingFangSCRegularFont(ofSize: 16))
if let width = contentSize?.width, textViewWidth > 0 {
var numLine = Int(ceil(width / textViewWidth))
if numLine > currentLineNum {
textView.snp.updateConstraints { (make) in
make.height.equalTo(24 + numLine * 24)
}
} else if (numLine < currentLineNum) {
if numLine <= 1 {
textView.snp.updateConstraints { (make) in
make.height.equalTo(48)
}
} else {
textView.snp.updateConstraints { (make) in
make.height.equalTo(24 + numLine * 24)
}
}
}
if numLine == 0 {
numLine = 1
}
currentLineNum = numLine
}
}
本文标题:UITextView动态改变高度
本文链接:https://www.haomeiwen.com/subject/nrsaahtx.html
网友评论