A super fast and easy-to-use layout library for iOS. FrameLayoutKit supports complex layouts, including chaining and nesting layout with simple and intuitive operand syntax.
It simplifies the UI creation process, resulting in cleaner and more maintainable code.
Say NO to autolayout constraint nightmare:
Autolayout | FrameLayoutKit |
![]() |
![]() |
- Installation
- Core Components
- Basic Usage
- DSL Syntax
- Examples
- Performance
- Requirements
- Author
- License
FrameLayoutKit is available through Swift Package Manager
(Recommended) and CocoaPods:
Regardless of the method, make sure to import the framework into your project:
import FrameLayoutKit
Swift Package Manager is recommended to install FrameLayoutKit.
- Click
File
Add Packages...
- Enter the git URL for FrameLayoutKit:
https://github.com/kennic/FrameLayoutKit.git
FrameLayoutKit can also be installed as a CocoaPod. To install, add the following line to your Podfile:
pod "FrameLayoutKit"
FrameLayoutKit includes the following core components:
The most basic class, manages a single view and adjusts its size and position based on configured properties.
Manages multiple views in rows (horizontal) or columns (vertical), similar to UIStackView
but with higher performance and more options.
- HStackLayout: Horizontal layout
- VStackLayout: Vertical layout
- ZStackLayout: Stacked layout (z-index)
Arranges views in a grid, with customizable number of columns and rows.
Arranges views in a flow, automatically wrapping to the next line when there's not enough space.
Manages two views with various layout options.
Combines UIScrollView
with StackFrameLayout
to create a scrollview that can automatically layout its child views.
See Tutorial by Codebase2Tutorial (Recommended)
Read full document by DeepWiki
// Create a vertical layout
let vStackLayout = VStackLayout()
vStackLayout.spacing = 10
vStackLayout.distribution = .center
vStackLayout.padding(top: 20, left: 20, bottom: 20, right: 20)
// Add views to the layout
vStackLayout.add(view1)
vStackLayout.add(view2)
vStackLayout.add(view3)
// Add the layout to a parent view
parentView.addSubview(vStackLayout)
// Update the layout's frame
vStackLayout.frame = parentView.bounds
FrameLayoutKit provides the +
operator syntax to easily add views to layouts:
// Add a single view
vStackLayout + view1
// Add an array of views
vStackLayout + [view1, view2, view3]
// Add spacing
vStackLayout + 10 // Add 10pt spacing
// Add a child layout
vStackLayout + hStackLayout
// Configure alignment
(vStackLayout + view1).alignment = (.center, .fill)
// Configure fixed size
(vStackLayout + view2).fixedSize = CGSize(width: 100, height: 50)
// Add a flexible view (can expand)
(vStackLayout + view3).flexible()
vStackLayout
.distribution(.center)
.spacing(16)
.flexible()
.fixedHeight(50)
.aligns(.top, .center)
.padding(top: 20, left: 20, bottom: 20, right: 20)
FrameLayoutKit provides a DSL (Domain Specific Language) syntax similar to SwiftUI, making layout creation more intuitive and readable:
// Create VStackLayout with DSL syntax
let vStackLayout = VStackView {
titleLabel
descriptionLabel
SpaceItem(20) // Add a 20pt space
Item(actionButton).minWidth(120) // Customize the button's minimum width
}
// Create HStackLayout with DSL syntax
let hStackLayout = HStackView {
StackItem(imageView).fixedSize(width: 50, height: 50)
VStackView {
titleLabel
subtitleLabel
}.spacing(5)
FlexibleSpace() // Add flexible space
StackItem(button).align(vertical: .center, horizontal: .right)
}
- StackItem: Wraps a view to add to a stack with additional options
- SpaceItem: Adds fixed spacing
- FlexibleSpace: Adds flexible spacing (can expand)
- Item: Similar to StackItem but with more options
Here are some examples of how FrameLayoutKit works:
- targetView: The view managed by this layout
- edgeInsets: Padding around the view
- contentAlignment: Content alignment (top, center, bottom, left, right, fill, fit)
- Size & Content Size:
minSize/maxSize
,fixedSize
: Minimum/maximum/fixed size of the layout.minContentSize/maxContentSize
,fixedContentSize
: Minimum/maximum/fixed size of thetargetView
.extendSize (extendWidth, extendHeight)
: Additional size for thecontentSize
.heightRatio
: Defines height based on width.isIntrinsicSizeEnabled
: Controls ifsizeThatFits
usestargetView
's intrinsic size.
- Flexibility & Layout Behavior:
isFlexible
,flexibleRatio
: For flexible layouts within a stack.allowContentVerticalGrowing/Shrinking
,allowContentHorizontalGrowing/Shrinking
: Controls howtargetView
adapts toFrameLayout
's bounds.
- View Hierarchy & State:
parent
: The containingFrameLayout
.bindingViews
,bindingEdgeInsets
,lazyBindingViews
: For binding other views totargetView
's frame.ignoreHiddenView
,isEnabled
,isEmpty
: Control layout behavior based on visibility and enabled state.
- Positioning:
translationOffset (translationX, translationY)
: For manual position adjustments.
- Callbacks:
willSizeThatFitsBlock
: A block that will be called beforesizeThatFits
is called.willLayoutSubviewsBlock
: A block that will be called beforelayoutSubviews
is called.didLayoutSubviewsBlock
: A block that will be called afterlayoutSubviews
has finished.
- Debugging:
debug
,debugColor
: For visualizing layout frames.
- Skeleton Mode:
isSkeletonMode
,skeletonView
,skeletonColor
,skeletonMinSize
,skeletonMaxSize
: For displaying placeholder content.
- Performance:
shouldCacheSize
: CachessizeThatFits
results.
- Core Layout & Distribution:
axis
: Direction of the stack (vertical or horizontal). You can useVStackLayout
(vertical axis),HStackLayout
(horizontal axis).distribution
: How child views are distributed and space is allocated (e.g.,top
,center
,bottom
,left
,right
,fill
,equal
,split
).spacing
: Space between child views.isOverlapped
: Allows child views to overlap.ZStackLayout
automatically sets this totrue
.isJustified
,justifyThreshold
: Enables even distribution of child views.justifyThreshold
is the minimum remaining space required to trigger justification.
- Child Item Management:
frameLayouts
: Array of childFrameLayout
s.numberOfFrameLayouts
: Get or set the number of child layouts.firstFrameLayout
,lastFrameLayout
: Access the first and last child layout.frameLayout(at: Int)
,frameLayout(with: UIView)
: Retrieve specific child layouts.enumerate(_ block: (FrameLayout, Int, inout Bool) -> Void)
: Iterate over child layouts.- Item Management Methods: Includes functions like
add()
,insert()
,removeFrameLayout()
,removeAll()
,replace()
,addSpace()
, andinvert()
for managing child items. setUserInteraction(enabled: Bool)
: SetsisUserInteractionEnabled
for the stack and all its child layouts.
- Child Item Defaults & Property Propagation:
minItemSize
,maxItemSize
,fixedItemSize
: Sets default min/max/fixed content size for all childFrameLayout
s added to the stack.- Property Propagation: Many common
FrameLayout
properties (e.g.,ignoreHiddenView
,allowContent...Growing/Shrinking
,debug
,skeletonMode
,clipsToBounds
,shouldCacheSize
) when set on aStackFrameLayout
are propagated to its childFrameLayout
s.
FrameLayoutKit is one of the fastest layout libraries.
See: Layout libraries benchmark's project
- iOS 11.0+
- Swift 5.0+
Nam Kennic, [email protected]
FrameLayoutKit is available under the MIT license. See the LICENSE file for more info.