我一直在尝试找到一种方法来调整整个地方的UItextview的高度,但是找不到答案。因此,我正在寻求您的帮助。我没有使用情节提要进行限制。如何根据内容大小使UITextView的高度动态变化?感谢您的帮助!我已附上一张图片,以显示textview的外观。
scrollView.addSubview(itemTitleView)
itemTitleView.topAnchor.constraintEqualToAnchor(itemImage.bottomAnchor, constant: 80).active = true
itemTitleView.widthAnchor.constraintEqualToAnchor(itemImage.widthAnchor).active = true
itemTitleView.heightAnchor.constraintEqualToConstant(56).active = true
itemTitleView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
尝试将此扩展名用于字符串。如果您知道宽度将是多少,这将为您提供所需的高度。您只需要宽度和字体,它就可以工作。
extension String {
func heightWithConstrainedWidth(width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: CGFloat.max)
let boundingBox = self.boundingRectWithSize(constraintRect, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
return boundingBox.height
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句