I have following setup in the xib file
ScrollView (UIScrollView)
- ContentView (UIView)
- ImageSlider (FSPagerView)
- ClinicName (UILabel)
- ClinicSlogan (UILabel)
- LineSeparatorView (UIView)
- ClinicProfile (UITextView)
- SectionView (Custom UIView)
- Doctors View (UICollectionView) - Horizontal Scrolling
Constraints are setup in IB the following way
// ScrollView Constraints
ScrollView.Top = NavigationView.Bottom
ScrollView.Leading = SafeArea.Leading
SafeArea.Trailing = ScrollView.Trailing
SafeArea.Bottom = ScrollView.Bottom
// ContentView Constraints
ContentView.Top = SuperView.Top
ContentView.Leading = SuperView.Leading
SuperView.Trailing = ContentView.Trailing
SuperView.Bottom = ContentView.Bottom
ContentView.Height = SuperView.Height (Priority@250)
ContentView.Width = SuperView.Width
All constraints for subviews inside ContentView are set related to SuperView (ContentView)
In viewDidLoad()
I am updating the text value of ClinicSlogan and ClinicProfile and updating the height constant. Which works, but when I update the height of scroll view it does not work, here are the code I am calling in below of viewDidLoad()
self.clinicSloganLabelHeightConstraint.constant = estimatedFrameFor(
text: self.clinicSloganLabel.text!,
font: self.clinicSloganLabel.font!,
width: self.clinicSloganLabel.frame.width
).height
self.clinicProfileTextViewHeightConstraint.constant = self.clinicProfileTextView.sizeThatFits(
CGSize(width: self.clinicProfileTextView.frame.width, height: .infinity)
).height
self.scrollView.contentSize.height = 2000
I tried placing the code in viewDidLayoutSubviews() the problem is, I am using UICollectionView() inside ScrollView() which stops scrolling the moment viewDidLayoutSubviews method is invoked.
Can you help to go in the right direction on updating the height of scroll view in UIViewController subclass?
Thank you
Alright, I solved it using Autolayout in IB, what I did is, the last view I added "Bottom Space To Container" constraint to Content View, and now all of content is automatically adjusting.