Search code examples
iosswiftuiscrollviewcartography

UIScrollView contentSize height using Cartography


I'm working on app and decided to use UIScrollView. I'm using Cartography to set the elements constraints inside of the UIScrollView.

My question is: On Cartography, we can get bottom position of element with element.bottom, is there a way to use this position to set the UIScrollView contentSize height? I know what is the last one element.


Solution

  • According to this answer on the Github Cartography project, this is not poissible.

    Not sure what you mean, but view.bottom is not a value but rather a variable symbolic (after all, it's Auto Layout's job to figure out the value).

    Now what most strikes me is that if I set the constraints manually, without using Cartography, this works correctly.

    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0(\(getScreenSize().width * 0.68))]-25-[v1][v2(\(textViewHeight))][v3(44)]-20-[v4(32)][v5(300)]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": imageView, "v1": titleTextView, "v2": textView, "v3": stackView, "v4": galleryHeader, "v5": collectionView]))