Skip to content

Commit 7e94cc0

Browse files
committed
#10 Added documentation to support plain UIView
1 parent cb45031 commit 7e94cc0

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ You can think of it as `UITableView` but with several differences:
3030
|--- |--------------------------------------------------------------------------------- |
3131
| 🕺 | Create complex layout without the boilerplate required by view recyling of `UICollectionView` or `UITableView`. |
3232
| 🧩 | Simplify your architecture by thinking each screen as a separate-indipendent `UIVIewController`. |
33+
| 🧩 | Support for lightweight mode to layout `UIView` without `UIViewController`. |
3334
| 🌈 | Animate show/hide and resize of rows easily even with custom animations! |
3435
|| Compact code base, less than 1k LOC with no external dependencies. |
3536
| 🎯 | Easy to use and extensible APIs set. |
@@ -53,6 +54,7 @@ You can think of it as `UITableView` but with several differences:
5354
- [Fitting Layout Row Size](#fittinglayoutrowsize)
5455
- [Collapsible Rows](#collapsiblerows)
5556
- [Working with dynamic UICollectionView/UITableView/UITextView](#workingwithdynamicuicollectionviewuitableviewuitextview)
57+
- [Using plain UIViews instead of view controllers](#lightweightplainuiview)
5658
- [Rows Separator](#rowsseparator)
5759
- [Tap On Rows](#taponrows)
5860
- [Get the row/controller](#utilsmethods)
@@ -500,6 +502,27 @@ Moreover you can set these values directly on `ScrollStack` controller in order
500502

501503
[↑ Back To Top](#index)
502504

505+
<a name="lightweightplainuiview"/>
506+
507+
### Using plain UIViews instead of view controllers
508+
509+
Since version 1.3.x ScrollStack can also be used to layout plain `UIView` instances which not belong to a parent view controllers.
510+
This is especially useful when you don't have a complex logic in your views and you want to use ScrollStack to make custom layout and keep your code lightweight.
511+
512+
Using plain views is pretty easy; each row method supports both `UIView` or `UIViewController` as parameter.
513+
514+
Since you are working with plain `UIView` instances in order to size it correctly you must set its `heightAnchor` or `widthAncor` (depending of your stack orientation) before adding it to the stack.
515+
As for controllers, `ScrollStack` keeps a strong reference to the managed view which is added as `contentView` of the parent `ScrollStackRow` instance as it happens for `UIViewController`'s `.view` property.
516+
517+
This is a small example:
518+
519+
```swift
520+
let myCustomView = UIView(frame: .zero)
521+
myCustomView.backgroundColor = .green
522+
myCustomView.heightAnchor.constraint(equalToConstant: 300).isActive = true
523+
stackView.addRow(view: myCustomView)
524+
```
525+
503526
<a name="taponrows"/>
504527

505528
### Tap On Rows

ScrollStackControllerDemo/ViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ class ViewController: UIViewController, ScrollStackControllerDelegate {
5050
pricingVC = PricingVC.create(delegate: self)
5151
notesVC = NotesVC.create(delegate: self)
5252

53-
stackView.addRows(controllers: [welcomeVC, notesVC, tagsVC, galleryVC,pricingVC], animated: false)
53+
let v = UIView(frame: .zero)
54+
v.backgroundColor = .green
55+
v.heightAnchor.constraint(equalToConstant: 300).isActive = true
56+
stackView.addRow(view: v)
57+
58+
// stackView.addRows(controllers: [welcomeVC, notesVC, tagsVC, galleryVC,pricingVC], animated: false)
5459
}
5560

5661
@IBAction public func addNewRow() {

0 commit comments

Comments
 (0)