解决方案:
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://*.com/questions/50467/how-do-i-size-a-uitextview-to-its-content/2487402#2487402