如何在动态uitextview下添加固定视图?
How can I add a fixed view under dynamic uitextview?
我有一个 UITextView 对象。我想在下面添加另一个视图,但 TextView 填满了整个屏幕。找不到怎么办。我想要做的是在滚动完成时显示固定视图。我该怎么做?
不要使用 textViews 自己的 scrollView 进行滚动。
而是设置一个包含 textView 和您的 footerView 的外部 scrollView(通过嵌入 stackView 或设置您自己的约束)。
正确调整文本和滚动视图的大小可能很棘手。
详情请参考this guide
总结一下:
- Add UIScrollView inside the main view in Storyboard
- Add UIView inside the UIScrollView
- Add UITextView inside the UIView (the view added in step 2)
- Make sure "Scrolling Enabled" of UITextView is unchecked
- Add 4 constraints (leading, trailing, top, bottom) on UIScrollView
- Add 4 constraints (leading, trailing, top, bottom) on UIView (the view added in step 2)
- Add "Width Equally" constraint on UIView (the view added in step 2) and the main view
- Add 5 constraints (leading, trailing, top, bottom, height) on UITextView. After this step you shouldn't get any errors and warnings on constraints.
- Add UITextView height constraint IBOutlet on the ViewController.
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint;
and connect it in Storyboard
- Change the UITextView height constraint programmatically.
self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;
我有一个 UITextView 对象。我想在下面添加另一个视图,但 TextView 填满了整个屏幕。找不到怎么办。我想要做的是在滚动完成时显示固定视图。我该怎么做?
不要使用 textViews 自己的 scrollView 进行滚动。
而是设置一个包含 textView 和您的 footerView 的外部 scrollView(通过嵌入 stackView 或设置您自己的约束)。
正确调整文本和滚动视图的大小可能很棘手。
详情请参考this guide
总结一下:
- Add UIScrollView inside the main view in Storyboard
- Add UIView inside the UIScrollView
- Add UITextView inside the UIView (the view added in step 2)
- Make sure "Scrolling Enabled" of UITextView is unchecked
- Add 4 constraints (leading, trailing, top, bottom) on UIScrollView
- Add 4 constraints (leading, trailing, top, bottom) on UIView (the view added in step 2)
- Add "Width Equally" constraint on UIView (the view added in step 2) and the main view
- Add 5 constraints (leading, trailing, top, bottom, height) on UITextView. After this step you shouldn't get any errors and warnings on constraints.
- Add UITextView height constraint IBOutlet on the ViewController.
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint;
and connect it in Storyboard- Change the UITextView height constraint programmatically.
self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;