1

I have a UITextView Object. I want to add another view under but the TextView fills the whole screen. Couldn't find how to do. What I want to do is show a fixed view when the scroll is finished. How can I do it?

  • you can use tableviews adding the view in the last row/section of the table view. It is difficult to help you if we don't see how you implemented your code. – Mat Feb 14 '21 at 07:49
  • Please review [ask]. From your question, we have no idea what you mean by *"dynamic UITextView"* or *"fills the whole screen"* or *"when the scroll is finished"*. – DonMag Feb 14 '21 at 14:17

1 Answers1

0

Don't use the textViews own scrollView for scrolling.
Instead setup an outer scrollView that contains the textView and your footerView (either by embedding in a stackView or by setting up your own constraints).
Getting text and scrollView resizing right can be tricky.
Please refer to this guide for details.

To summarize:

  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;
de.
  • 7,068
  • 3
  • 40
  • 69