Created
May 17, 2018 20:22
-
-
Save ericjkunz/4ad936cade43ed5e10f7554210651ad6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| extension UIStackView { | |
| open override var intrinsicContentSize: CGSize { | |
| var size = arrangedSubviews.reduce(CGSize.zero) { size, view -> CGSize in | |
| var size = size | |
| switch axis { | |
| case .horizontal: | |
| size.width += view.intrinsicContentSize.width | |
| size.height = max(size.height, view.intrinsicContentSize.height) | |
| case .vertical: | |
| size.height += view.intrinsicContentSize.height | |
| size.width = max(size.width, view.intrinsicContentSize.width) | |
| } | |
| return size | |
| } | |
| switch axis { | |
| case .horizontal: | |
| size.width += spacing * CGFloat(arrangedSubviews.count - 1) | |
| case .vertical: | |
| size.height += spacing * CGFloat(arrangedSubviews.count - 1) | |
| } | |
| return size | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using UIStackView().systemLayoutSizeFitting(UILayoutFittingCompressedSize) seems to work just as well.