如何在动态uitextview下添加固定视图?

How can I add a fixed view under dynamic uitextview?

我有一个 UITextView 对象。我想在下面添加另一个视图,但 TextView 填满了整个屏幕。找不到怎么办。我想要做的是在滚动完成时显示固定视图。我该怎么做?

不要使用 textViews 自己的 scrollView 进行滚动。
而是设置一个包含 textView 和您的 footerView 的外部 scrollView(通过嵌入 stackView 或设置您自己的约束)。
正确调整文本和滚动视图的大小可能很棘手。
详情请参考this guide

总结一下:

  1. Add UIScrollView inside the main view in Storyboard
  2. Add UIView inside the UIScrollView
  3. Add UITextView inside the UIView (the view added in step 2)
  4. Make sure "Scrolling Enabled" of UITextView is unchecked
  5. Add 4 constraints (leading, trailing, top, bottom) on UIScrollView
  6. Add 4 constraints (leading, trailing, top, bottom) on UIView (the view added in step 2)
  7. Add "Width Equally" constraint on UIView (the view added in step 2) and the main view
  8. Add 5 constraints (leading, trailing, top, bottom, height) on UITextView. After this step you shouldn't get any errors and warnings on constraints.
  9. Add UITextView height constraint IBOutlet on the ViewController. @property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint; and connect it in Storyboard
  10. Change the UITextView height constraint programmatically. self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;