https://github.com/99yuseong/spacer
SwiftUI spacer() modifier to add flexible spacing to your views.
https://github.com/99yuseong/spacer
infinity layout maxheight maxwidth spacer swiftui ui
Last synced: 2 months ago
JSON representation
SwiftUI spacer() modifier to add flexible spacing to your views.
- Host: GitHub
- URL: https://github.com/99yuseong/spacer
- Owner: 99yuseong
- License: mit
- Created: 2024-10-30T13:07:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-08T04:56:15.000Z (over 1 year ago)
- Last Synced: 2025-02-23T04:32:32.503Z (over 1 year ago)
- Topics: infinity, layout, maxheight, maxwidth, spacer, swiftui, ui
- Language: Swift
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spacer
A Swift Package that simplifies layout adjustments by allowing the placement of spacers based on `Edge.Set` positions. This package helps maintain clean, readable code while enhancing layout flexibility in SwiftUI.
## Features
- Place `Spacer` in specific locations (`.leading`, `.trailing`, `.top`, `.bottom`, `.horizontal`, `.vertical` `.all`) with a single modifier.
- Set minimum lengths for each spacer, providing full control over layout gaps.
- Streamline complex layouts while keeping SwiftUI code readable.
## Usage
Use `.spacer()` modifier with `Edge.Set` and optional `minLength` to add flexible spacing to your views.
### Ex) Leading Spacer
```swift
Text("Leading Text")
.spacer(.leading)
```
### Ex) Trailing Spacer
```swift
Text("Trailing Text")
.spacer(.trailing, minLength: 10)
```
### Ex) Spacer for vertical stacks
```swift
import Spacer
struct ContentView: View {
var body: some View {
VStack {
MyLabel("My Label")
.spacer(.trailing)
MyButton("My Button") {
print("Button tapped")
}
.spacer(.bottom, minLength: 20)
}
}
}
```
## Requirements
- iOS 13.0+
## Installation
### Swift Package Manager
[Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate `Spacer` into your Xcode project using Swift Package Manager, add it to the dependencies value of your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/99yuseong/Spacer.git", .upToNextMajor(from: "1.0.0"))
]
```