Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cjnevin/AutoLayoutBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
cjnevin committed Oct 16, 2022
2 parents 93123f2 + c59f58f commit 74b16c9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@ addSubview(scrollView) {
}
```

### StackViews

There is actually a cleaner way of doing the above, it's called `ScrollableStackView` and you could write the above code as:

```swift
addSubview(ScrollableStackView {
redView
greenView
}.spacing(10, after: redView)) {
$0.edges == Superview()
}
```

Alternatively, if you need to store the stackView you could write it like this:

```swift
let stackView = ScrollableStackView()

...

addSubview(stackView.replaceStackedViews {
redView
greenView
}.spacing(10, after: redView)) {
$0.edges == Superview()
}
```

By default it will be vertical but you can pass in the `axis` to flip it to horizontal, it will take care of the constraints for you.

There is also a `StackView` component that works the same way but doesn't allow for scrolling.

## Relative Constraints

If you have several views all being added to the same superview you may have three separate blocks:
Expand Down

0 comments on commit 74b16c9

Please sign in to comment.