Class
ScrollableStack
public class ScrollableStack: UIScrollView
Relationships
Nested Types
ScrollableStack.Cell
A view that wraps every row in a
ScrollableStack
ScrollableStack.Errors
Conforms To
UIScrollView
Initializers
init()
public init()
Properties
axis
public var axis: NSLayoutConstraint.Axis
The direction that rows are laid out in the stack view.
If axis
is .vertical
, rows will be laid out in a vertical column. If axis
is
.horizontal
, rows will be laid out horizontally, side-by-side.
This property also controls the direction of scrolling in the stack view. If axis
is
.vertical
, the stack view will scroll vertically, and rows will stretch to fill the width of
the stack view. If axis
is .horizontal
, the stack view will scroll horizontally, and rows
will be sized to fill the height of the stack view.
The default value is .vertical
.
firstRow
public var firstRow: UIView?
The first row in the stack view.
This property is nil if there are no rows in the stack view.
lastRow
public var lastRow: UIView?
The last row in the stack view.
This property is nil if there are no rows in the stack view.
rowInset
public var rowInset
Specifies the default inset of rows.
This inset will be used for any new row that is added to the stack view.
You can use this property to add space between a row and the left and right edges of the stack view and the rows above and below it. Positive inset values move the row inward and away from the stack view edges and away from rows above and below.
The default inset is 0pt all around.
rowBackgroundColor
public var rowBackgroundColor = UIColor.clear
The background color of rows in the stack view.
This background color will be used for any new row that is added to the stack view. The default color is clear.
rowHighlightColor
public var rowHighlightColor = ScrollableStack.defaultRowHighlightColor
The highlight background color of rows in the stack view.
This highlight background color will be used for any new row that is added to the stack view. The default color is #D9D9D9 (RGB 217, 217, 217).
automaticallyHidesLastSeparator
public var automaticallyHidesLastSeparator = true
Automatically hides the separator of the last cell in the stack view.
Default is true
.
hidesSeparatorsByDefault
public var hidesSeparatorsByDefault = true
Specifies the default visibility of row separators.
When true
, separators will be hidden for any new rows added to the stack view.
When false, separators will be visible for any new rows added. Default is
true`, meaning
separators are visible for any new rows that are added.
Methods
add(_:animated:)
func add(_ row: UIView, animated: Bool = false)
Adds a row to the end of the stack view.
If animated
is true
, the insertion is animated.
add(_:animated:)
func add(_ rows: [UIView], animated: Bool = false)
Adds multiple rows to the end of the stack view.
If animated
is true
, the insertions are animated.
prepend(_:animated:)
func prepend(_ row: UIView, animated: Bool = false)
Adds a row to the beginning of the stack view.
If animated
is true
, the insertion is animated.
prepend(_:animated:)
func prepend(_ rows: [UIView], animated: Bool = false)
Adds multiple rows to the beginning of the stack view.
If animated
is true
, the insertions are animated.
insert(_:before:animated:)
func insert(_ row: UIView, before beforeRow: UIView, animated: Bool = false)
Inserts a row above the specified row in the stack view.
If animated
is true
, the insertion is animated.
insert(_:before:animated:)
func insert(_ rows: [UIView], before beforeRow: UIView, animated: Bool = false)
Inserts multiple rows above the specified row in the stack view.
If animated
is true
, the insertions are animated.
insert(_:after:animated:)
func insert(_ row: UIView, after afterRow: UIView, animated: Bool = false)
Inserts a row below the specified row in the stack view.
If animated
is true
, the insertion is animated.
insert(_:after:animated:)
func insert(_ rows: [UIView], after afterRow: UIView, animated: Bool = false)
Inserts multiple rows below the specified row in the stack view.
If animated
is true
, the insertions are animated.
insert(_:at:animated:)
func insert(_ row: UIView, at index: Int, animated: Bool = false)
Inserts a new row at the specified index.
Parameters
Name | Type | Description |
---|---|---|
row | UIView |
The row to add. |
index | Int |
The index to place the row at. |
animated | Bool |
If |
remove(_:animated:)
func remove(_ row: UIView, animated: Bool = false)
Removes the given row from the stack view.
If animated
is true
, the removal is animated.
remove(_:animated:)
func remove(_ rows: [UIView], animated: Bool = false)
Removes the given rows from the stack view.
If animated
is true
, the removals are animated.
removeAllRows(keeping:animated:)
func removeAllRows(keeping rows: [UIView] = [], animated: Bool = false)
Removes all the rows in the stack view.
Parameters
Name | Type | Description |
---|---|---|
rows | [UIView] |
The rows that should be kept, if any. Defaults to an empty array. |
animated | Bool |
If true, the removals are animated. |
allRows()
func allRows() -> [UIView]
Returns an array containing of all the rows in the stack view.
The rows in the returned array are in the order they appear visually in the stack view.
contains(_:)
func contains(_ row: UIView) -> Bool
Returns true
if the given row is present in the stack view, false
otherwise.
configuredCell(for:)
func configuredCell(for row: UIView) -> ScrollableStack.Cell?
Returns the configured ScrollableStack.Cell
for the given row.
hide(_:animated:)
func hide(_ row: UIView, animated: Bool = false)
Hides the given row, making it invisible.
If animated
is true
, the change is animated.
hide(_:animated:)
func hide(_ rows: [UIView], animated: Bool = false)
Hides the given rows, making them invisible.
If animated
is true
, the changes are animated.
show(_:animated:)
func show(_ row: UIView, animated: Bool = false)
Shows the given row, making it visible.
If animated
is true
, the change is animated.
show(_:animated:)
func show(_ rows: [UIView], animated: Bool = false)
Shows the given rows, making them visible.
If animated
is true
, the changes are animated.
tapped(row:)
func tapped<RowView: UIView>(row: RowView) -> AnyPublisher<RowView, Never>
Creates a control event that will be invoked when the given row in the stack is tapped by the user.
The event will be passed the row.
setBackgroundColor(row:color:)
func setBackgroundColor(row: UIView, color: UIColor)
Sets the background color for the given row to the UIColor
provided.
setBackgroundColor(rows:color:)
func setBackgroundColor(rows: [UIView], color: UIColor)
Sets the background color for the given rows to the UIColor
provided.
setInset(row:inset:)
func setInset(row: UIView, inset: UIEdgeInsets)
Sets the inset for the given row to the UIEdgeInsets
provided.
setInset(rows:inset:)
func setInset(rows: [UIView], inset: UIEdgeInsets)
Sets the inset for the given rows to the UIEdgeInsets
provided.
setSeparatorInset(row:inset:)
func setSeparatorInset(row: UIView, inset: UIEdgeInsets)
Sets the separator inset for the given row to the UIEdgeInsets
provided.
Only left and right insets are honored.
setSeparatorInset(rows:inset:)
func setSeparatorInset(rows: [UIView], inset: UIEdgeInsets)
Sets the separator inset for the given rows to the UIEdgeInsets
provided.
Only left and right insets are honored.
scrollRowToVisible(_:animated:)
func scrollRowToVisible(_ row: UIView, animated: Bool = true)
Scrolls the given row onto screen so that it is fully visible.
If animated
is true
, the scroll is animated. If the row is already fully visible, this
method does nothing.
cellForRow(_:)
func cellForRow(_ row: UIView) -> ScrollableStack.Cell
Returns the ScrollableStack.Cell
to be used for the given row.
An instance of ScrollableStack.Cell
wraps every row in the stack view.
Subclasses can override this method to return a custom ScrollableStack.Cell
subclass, for example
to add custom behavior or functionality that is not provided by default.
If you customize the values of some properties of ScrollableStack.Cell
in this method, these values
may be overwritten by default values after the cell is returned. To customize the values of
properties of the cell, override configureCell(_:)
and perform the customization there,
rather than on the cell returned from this method.
configureCell(_:)
func configureCell(_ cell: ScrollableStack.Cell)
Allows subclasses to configure the properties of the given ScrollableStack.Cell
.
This method is called for newly created cells after the default values of any properties of the cell have been set by the superclass.
The default implementation of this method does nothing.