https://github.com/eneko/stripes
SwiftUI background stripes and other texture patterns
https://github.com/eneko/stripes
Last synced: 5 months ago
JSON representation
SwiftUI background stripes and other texture patterns
- Host: GitHub
- URL: https://github.com/eneko/stripes
- Owner: eneko
- License: mit
- Created: 2020-07-08T15:13:09.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-11-26T01:01:31.000Z (over 2 years ago)
- Last Synced: 2025-01-10T19:06:03.190Z (6 months ago)
- Language: Swift
- Size: 479 KB
- Stars: 114
- Watchers: 6
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Stripes
Beautiful background pattern views for SwiftUI.
## Example Patterns
### Diagonal Bars

```swift
import SwiftUI
import Stripesstruct ContentView: View {
var body: some View {
ZStack {
Stripes(config: .default)
Text("Hello, world!")
.font(.system(size: 50))
.foregroundColor(.white)
.bold()
}
.background(Color.black)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
}
}
```### Vertical Bars
```swift
import SwiftUI
import Stripesstruct ContentView: View {
var body: some View {
ZStack {
Stripes(config: StripesConfig(background: Color.green.opacity(0.6),
foreground: Color.white.opacity(0.3), degrees: 0,
barWidth: 50, barSpacing: 50))
Text("Hello, world!")
.font(.system(size: 50))
.foregroundColor(.white)
.bold()
}
.background(Color.black)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
}
}
```### Overlapping Patterns
```swift
import SwiftUI
import Stripesstruct ContentView: View {
var body: some View {
ZStack {
Stripes(config: StripesConfig(background: Color.red.opacity(0.2),
foreground: Color.blue.opacity(0.6),
degrees: 45, barWidth: 50, barSpacing: 20))
Stripes(config: StripesConfig(background: Color.red.opacity(0.2),
foreground: Color.white.opacity(0.15),
degrees: -45, barWidth: 50, barSpacing: 20))
Text("Hello, world!")
.font(.system(size: 50))
.foregroundColor(.white)
.bold()
}
.background(Color.black)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
}
}
```## Installation
### Preferred: Add package to Xcode project
1. In Xcode, tap on `File -> Swift Packages -> Add Package Dependency`
1. Enter the package URL `https://github.com/eneko/Stripes`

1. Ensure the library is added to the list of Frameworks & Libraries

### Avoid dependencies, copy the code
```swift
public struct StripesConfig {
var background: Color
var foreground: Color
var degrees: Double
var barWidth: CGFloat
var barSpacing: CGFloatpublic init(background: Color = Color.pink.opacity(0.5), foreground: Color = Color.pink.opacity(0.8),
degrees: Double = 30, barWidth: CGFloat = 20, barSpacing: CGFloat = 20) {
self.background = background
self.foreground = foreground
self.degrees = degrees
self.barWidth = barWidth
self.barSpacing = barSpacing
}public static let `default` = StripesConfig()
}public struct Stripes: View {
var config: StripesConfigpublic init(config: StripesConfig) {
self.config = config
}public var body: some View {
GeometryReader { geometry in
let longSide = max(geometry.size.width, geometry.size.height)
let itemWidth = config.barWidth + config.barSpacing
let items = Int(2 * longSide / itemWidth)
HStack(spacing: config.barSpacing) {
ForEach(0..