Skip to content

GridView

A generic grid layout view that arranges child views in a responsive grid. Supports both portrait and landscape orientations with configurable maximum item count.

Initializer parameters

ParameterTypeRequiredDefaultDescription
maxItemsUInt9Maximum number of items the grid can display
showingCurrentlyUInt-Number of items currently visible in the grid
getChildView@escaping () -> CellContainerView-Factory closure that creates a new child view for each grid cell

Methods

MethodReturn TypeDescription
settingFrames(visibleItemCount:animation:completion:)VoidLays out child views in portrait orientation with optional animation
settingFramesForLandScape(visibleItemCount:animation:completion:)VoidLays out child views in landscape orientation with optional animation
childView(index:)CellContainerView?Returns the child view at the specified index
prepareForReuse(childView:)VoidPrepares a child view for reuse

Usage Examples

Basic Usage

Swift
import RealtimeKitUI
let gridView = GridView(
maxItems: 6,
showingCurrently: 4,
getChildView: {
return CellContainerView()
}
)
view.addSubview(gridView)

Update layout

Swift
import RealtimeKitUI
let gridView = GridView(
maxItems: 9,
showingCurrently: 3,
getChildView: {
return CellContainerView()
}
)
view.addSubview(gridView)
// Update layout with animation
gridView.settingFrames(
visibleItemCount: 4,
animation: true,
completion: {
print("Layout updated")
}
)