Skip to content

Commit 68df07e

Browse files
committed
Update README
1 parent 75351dc commit 68df07e

1 file changed

Lines changed: 189 additions & 72 deletions

File tree

README.md

Lines changed: 189 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# FrameLayoutKit
22

33
[![Platform](https://img.shields.io/cocoapods/p/FrameLayoutKit.svg?style=flat)](http://cocoapods.org/pods/FrameLayoutKit)
4-
[![Language](http://img.shields.io/badge/language-Swift-brightgreen.svg?style=flat
5-
)](https://developer.apple.com/swift)
4+
[![Language](http://img.shields.io/badge/language-Swift-brightgreen.svg?style=flat)](https://developer.apple.com/swift)
65
[![Version](https://img.shields.io/cocoapods/v/FrameLayoutKit.svg?style=flat-square)](http://cocoapods.org/pods/FrameLayoutKit)
76
[![SwiftPM Compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
87
[![License](https://img.shields.io/cocoapods/l/FrameLayoutKit.svg?style=flat-square)](http://cocoapods.org/pods/FrameLayoutKit)
@@ -13,8 +12,7 @@ A super fast and easy-to-use layout library for iOS. FrameLayoutKit supports com
1312

1413
It simplifies the UI creation process, resulting in cleaner and more maintainable code.
1514

16-
17-
## Why?
15+
## Why Use FrameLayoutKit?
1816

1917
Say NO to autolayout constraint nightmare:
2018

@@ -30,38 +28,183 @@ Say NO to autolayout constraint nightmare:
3028
</tr>
3129
</table>
3230

31+
## Table of Contents
32+
33+
- [Installation](#installation)
34+
- [Core Components](#core-components)
35+
- [Basic Usage](#basic-usage)
36+
- [DSL Syntax](#dsl-syntax)
37+
- [Examples](#examples)
38+
- [Performance](#performance)
39+
- [Requirements](#requirements)
40+
- [Author](#author)
41+
- [License](#license)
3342

34-
# Installation
43+
## Installation
3544

3645
FrameLayoutKit is available through `Swift Package Manager` (Recommended) and [CocoaPods](http://cocoapods.org):
3746

38-
Regardless, make sure to import the project wherever you may use it:
47+
Regardless of the method, make sure to import the framework into your project:
3948

4049
```swift
4150
import FrameLayoutKit
4251
```
4352

44-
### Cocoapods:
45-
FrameLayoutKit can be installed as a [CocoaPod](https://cocoapods.org/). To install, include this in your Podfile.
53+
### Swift Package Manager (Recommended)
54+
55+
[Swift Package Manager](https://swift.org/package-manager/) is recommended to install FrameLayoutKit.
56+
57+
1. Click `File`
58+
2. `Add Packages...`
59+
3. Enter the git URL for FrameLayoutKit:
60+
61+
```swift
62+
https://github.com/kennic/FrameLayoutKit.git
63+
```
64+
65+
### CocoaPods
66+
67+
FrameLayoutKit can also be installed as a [CocoaPod](https://cocoapods.org/). To install, add the following line to your Podfile:
4668

4769
```ruby
4870
pod "FrameLayoutKit"
4971
```
5072

73+
## Core Components
5174

52-
### Swift Package Manager
53-
[Swift Package Manager](https://swift.org/package-manager/) is recommended to install FrameLayoutKit.
75+
![image](images/FrameLayoutKit.png)
76+
77+
FrameLayoutKit includes the following core components:
78+
79+
### FrameLayout
80+
81+
The most basic class, manages a single view and adjusts its size and position based on configured properties.
82+
83+
### StackFrameLayout
84+
85+
Manages multiple views in rows (horizontal) or columns (vertical), similar to `UIStackView` but with higher performance and more options.
86+
87+
- **HStackLayout**: Horizontal layout
88+
- **VStackLayout**: Vertical layout
89+
- **ZStackLayout**: Stacked layout (z-index)
90+
91+
### GridFrameLayout
92+
93+
Arranges views in a grid, with customizable number of columns and rows.
94+
95+
### FlowFrameLayout
96+
97+
Arranges views in a flow, automatically wrapping to the next line when there's not enough space.
98+
99+
### DoubleFrameLayout
54100

55-
1. Click `File`
56-
2. `Add Packages...`
57-
3. Specify the git URL for FrameLayoutKit.
101+
Manages two views with various layout options.
102+
103+
### ScrollStackView
104+
105+
Combines `UIScrollView` with `StackFrameLayout` to create a scrollview that can automatically layout its child views.
106+
107+
## Basic Usage
108+
109+
### Creating and Configuring Layouts
58110

59111
```swift
60-
https://github.com/kennic/FrameLayoutKit.git
112+
// Create a vertical layout
113+
let vStackLayout = VStackLayout()
114+
vStackLayout.spacing = 10
115+
vStackLayout.distribution = .center
116+
vStackLayout.padding(top: 20, left: 20, bottom: 20, right: 20)
117+
118+
// Add views to the layout
119+
vStackLayout.add(view1)
120+
vStackLayout.add(view2)
121+
vStackLayout.add(view3)
122+
123+
// Add the layout to a parent view
124+
parentView.addSubview(vStackLayout)
125+
126+
// Update the layout's frame
127+
vStackLayout.frame = parentView.bounds
128+
```
129+
130+
### Using Operator Syntax (Recommended)
131+
132+
FrameLayoutKit provides the `+` operator syntax to easily add views to layouts:
133+
134+
```swift
135+
// Add a single view
136+
vStackLayout + view1
137+
138+
// Add an array of views
139+
vStackLayout + [view1, view2, view3]
140+
141+
// Add spacing
142+
vStackLayout + 10 // Add 10pt spacing
143+
144+
// Add a child layout
145+
vStackLayout + hStackLayout
146+
```
147+
148+
### Configuring View Properties
149+
150+
```swift
151+
// Configure alignment
152+
(vStackLayout + view1).alignment = (.center, .fill)
153+
154+
// Configure fixed size
155+
(vStackLayout + view2).fixedSize = CGSize(width: 100, height: 50)
156+
157+
// Add a flexible view (can expand)
158+
(vStackLayout + view3).flexible()
159+
```
160+
161+
### Chained Syntax (Recommended)
162+
163+
```swift
164+
vStackLayout
165+
.distribution(.center)
166+
.spacing(16)
167+
.flexible()
168+
.fixedHeight(50)
169+
.aligns(.top, .center)
170+
.padding(top: 20, left: 20, bottom: 20, right: 20)
61171
```
62172

63-
# Example
64-
Some examples of how FrameLayoutKit works:
173+
## DSL Syntax
174+
175+
FrameLayoutKit provides a DSL (Domain Specific Language) syntax similar to SwiftUI, making layout creation more intuitive and readable:
176+
177+
```swift
178+
// Create VStackLayout with DSL syntax
179+
let vStackLayout = VStackView {
180+
titleLabel
181+
descriptionLabel
182+
SpaceItem(20) // Add a 20pt space
183+
Item(actionButton).minWidth(120) // Customize the button's minimum width
184+
}
185+
186+
// Create HStackLayout with DSL syntax
187+
let hStackLayout = HStackView {
188+
StackItem(imageView).fixedSize(width: 50, height: 50)
189+
VStackView {
190+
titleLabel
191+
subtitleLabel
192+
}.spacing(5)
193+
FlexibleSpace() // Add flexible space
194+
StackItem(button).align(vertical: .center, horizontal: .right)
195+
}
196+
```
197+
198+
### Main DSL Components
199+
200+
- **StackItem**: Wraps a view to add to a stack with additional options
201+
- **SpaceItem**: Adds fixed spacing
202+
- **FlexibleSpace**: Adds flexible spacing (can expand)
203+
- **Item**: Similar to StackItem but with more options
204+
205+
## Examples
206+
207+
Here are some examples of how FrameLayoutKit works:
65208

66209
<table>
67210
<tr><td> Source </td> <td> Result </td></tr>
@@ -82,10 +225,11 @@ frameLayout + VStackLayout {
82225
}.spacing(5.0)
83226

84227
frameLayout
85-
.spacing(15)
86-
.padding(top: 15, left: 15, bottom: 15, right: 15)
87-
.debug(true) // show dashed lines to visualize the layout
88-
```
228+
.spacing(15)
229+
.padding(top: 15, left: 15, bottom: 15, right: 15)
230+
.debug(true) // show dashed lines to visualize the layout
231+
232+
````
89233
</td>
90234
<td>
91235
<img alt="result 1" src="images/helloWorld.png">
@@ -108,7 +252,8 @@ let frameLayout = VStackLayout {
108252
}.padding(top: 12, left: 12, bottom: 12, right: 12)
109253
.distribution(.bottom)
110254
.spacing(5)
111-
```
255+
````
256+
112257
</td>
113258
<td>
114259
<img alt="result 1" src="images/example_1.png">
@@ -135,6 +280,7 @@ frameLayout + VStackLayout {
135280
}.spacing(12).padding(top: 0, left: 12, bottom: 12, right: 12)
136281
}.distribution(.bottom)
137282
```
283+
138284
</td>
139285
<td>
140286
<img alt="result 2" src="images/example_2.png">
@@ -165,79 +311,50 @@ cardView + HStackLayout {
165311
.forEach { $0.fixedContentSize(buttonSize) }
166312
}.distribution(.center).spacing(10)
167313
```
168-
</td>
169-
<td>
170-
<img alt="result 2" src="images/example_3.png">
171-
</td>
172-
</tr>
173-
</table>
174-
175-
Two types of code syntax:
176-
177-
<table>
178-
<tr><td>Regular syntax</td> <td>Chained syntax</td></tr>
179-
<tr>
180-
<td>
181314

182-
```swift
183-
frameLayout.distribution = .center
184-
frameLayout.spacing = 16
185-
frameLayout.isFlexible = true
186-
```
187315
</td>
188316
<td>
189-
190-
```swift
191-
frameLayout
192-
.distribution(.center)
193-
.spacing(16)
194-
.flexible()
195-
```
317+
<img alt="result 2" src="images/example_3.png">
196318
</td>
197319
</tr>
198320
</table>
199321

200-
## DSL Syntax
322+
## Key Properties
201323

202-
In `FrameLayoutKit`, DSL (Domain Specific Language) syntax provides a more declarative and readable way to define layouts, much like SwiftUI. This syntax is particularly used in `VStackView`, `HStackView`, and `ZStackView`. These views support DSL, allowing you to add standard UIKit views directly or customize them with `Item(view)` for more control over size and position. It simplifies the process of creating and managing layouts by offering a SwiftUI-like declarative approach, making your code more readable and easier to maintain.
324+
### FrameLayout
203325

204-
```swift
205-
let titleLabel = UILabel()
206-
let descriptionLabel = UILabel()
207-
let actionButton = UIButton()
326+
- **targetView**: The view managed by this layout
327+
- **edgeInsets**: Padding around the view
328+
- **minSize/maxSize**: Minimum/maximum size of the layout
329+
- **minContentSize/maxContentSize**: Minimum/maximum size of the child view
330+
- **fixedSize/fixedContentSize**: Fixed size of the layout/child view
331+
- **contentAlignment**: Content alignment (top, center, bottom, left, right, fill, fit)
332+
- **isFlexible**: Allows the layout to expand to fill available space
208333

209-
let vStackLayout = VStackView {
210-
titleLabel
211-
descriptionLabel
212-
SpaceItem(20) // Adds a space of 20 points
213-
Item(actionButton).minWidth(120) // Customizes the button's minimum width
214-
}
334+
### StackFrameLayout
215335

216-
```
336+
- **axis**: Direction of the stack (vertical, horizontal)
337+
- **distribution**: How child views are distributed (top, center, bottom, left, right, fill, fit, justified)
338+
- **spacing**: Space between child views
339+
- **isJustified**: Evenly distributes child views
340+
- **isOverlapped**: Allows child views to overlap
217341

218-
## Overall Structure
219-
220-
![image](images/FrameLayoutKit.png)
342+
## Performance
221343

222-
# Benchmark
223344
FrameLayoutKit is one of the fastest layout libraries.
224345
![Benchmark Results](images/bechmark.png "Benchmark results")
225346

226347
See: [Layout libraries benchmark's project](https://github.com/layoutBox/LayoutFrameworkBenchmark)
227348

228-
# Todo
349+
## Requirements
229350

230-
- [x] Swift Package Manager
231-
- [x] CocoaPods support
232-
- [x] Objective-C version (Deprecated - Not recommended)
233-
- [x] Swift version
234-
- [x] Examples
235-
- [ ] Documents
351+
- iOS 11.0+
352+
- Swift 5.0+
236353

237-
# Author
354+
## Author
238355

239356
Nam Kennic, namkennic@me.com
240357

241-
# License
358+
## License
242359

243360
FrameLayoutKit is available under the MIT license. See the LICENSE file for more info.

0 commit comments

Comments
 (0)