Skip to content

acapellaonduty/DotPattern-SwiftUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

DotPattern

DotPattern is a Swift Package designed for SwiftUI applications, allowing you to add customizable dot patterns as backgrounds. This package is ideal for developers looking to maintain a consistent design language with dotted backgrounds across buttons, views, or other UI components.

Example Usage of DotPattern

Here’s an example of how to use DotPattern in your SwiftUI views: Below are some sample implementations of DotPattern with different configurations:

private func dotBackground(dotColor: Color, backgroundColor: Color, dotSize: CGFloat, spacing: CGFloat, opacity: Double, cornerRadius: CGFloat) -> some View {
        DotPattern(dotColor: dotColor, backgroundColor: backgroundColor, dotSize: dotSize, spacing: spacing, opacity: opacity)
            .clipShape(RoundedRectangle(cornerRadius: cornerRadius))
    }
 // MARK: Dot Pattern Button
            Button(action: {
                print("Button pressed")
            }) {
                Text("Dot Pattern Button")
                    .foregroundColor(.white)
                    .padding()
                    .background(
                        dotBackground(dotColor: .white, backgroundColor: .red.opacity(0.8), dotSize: 3, spacing: 3, opacity: 0.2, cornerRadius: 12)
              )
            }
// MARK: Dot Pattern Button
 // MARK: Card with Dot Pattern Overlay
            RoundedRectangle(cornerRadius: 15)
                .fill(Color.white)
                .frame(height: 150)
                .overlay(
                    dotBackground(dotColor: .gray, backgroundColor: .clear, dotSize: 4, spacing: 6, opacity: 0.1, cornerRadius: 15)
                )
                .shadow(radius: 5)
                .padding()
                .overlay(Text("Card with Dot Pattern").foregroundColor(.blue))
// MARK: Card with Dot Pattern Overlay

Core Functionalities

  • Dot Color: Customize the color of the dots.
  • Background Color: Set the background color behind the dots.
  • Dot Size: Adjust the size of the dots.
  • Spacing: Control the spacing between dots.
  • Opacity: Adjust the opacity of the dots for subtle or more prominent patterns.

Requirements

  • iOS: 17.0 or newer
  • Swift: 5.0 or newer
  • SwiftUI

Installation

Swift Package Manager

You can add DotPattern to your project using Swift Package Manager or by directly copying the code into your project.

1. Using Swift Package Manager:

  1. In Xcode, go to File > Add Packages.
  2. Enter the repository URL: [https://github.com/acapellaonduty/DotPattern].
  3. Select Add Package.

2. Directly Adding the Code:

If you prefer to add DotPattern directly to your project, you can simply copy the code from the repository and include it in your project files. For better performance

  1. Copy the DotPattern.swift file.
  2. Paste it into your project folder in Xcode.

To improve performance when rendering a large number of dots, consider caching the pattern. Without caching, rendering too many dots dynamically might lead to performance issues. By pre-rendering the dot pattern into an image or a reusable layer, you can significantly reduce the computational load and ensure smoother performance.

Contact

For any questions or feedback, you can reach me at:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages