解决方案:
1.定义一个textview,在storyboard中设定该textview的constraints。
2.将高度的constraint定义到头文件中:(直接拖拽)
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textviewHeightConstraint;3.待在实现文件中为textview加载了内容之后,获取文本高度,为该constraint赋值:
CGSize sizeThatShouldFitTheContent = [self.shippingAddressTextView sizeThatFits:self.shippingAddressTextView.frame.size]; self.textviewHeightConstraint.constant = sizeThatShouldFitTheContent.height;
参考链接:
http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content/2487402#2487402
iOS 根据文本内容为TextView动态定义高度,布布扣,bubuko.com
原文地址:http://blog.csdn.net/willyang519/article/details/37618961