SmoothGradient SwiftUI Framework

repository·main·Indexed 41 days ago

https://github.com/raymondjavaxx/smoothgradient

A SwiftUI framework that replaces standard linear gradients with smoother transitions using easing functions to prevent hard edges. Supports SmoothLinearGradient for iOS 17+ and macOS 14+, and a .smooth(from:to:curve:) modifier for older versions.

Tokens
635
Snippets
4
Records
4
Agent score
2%

What's inside SmoothGradient

  1. Install SmoothGradient via Swift Package Manager

    main

    To integrate SmoothGradient into your Xcode project using Swift Package Manager, add the repository URL to your Package.swift or use the Xcode GUI.

    Via Xcode GUI:

    1. Go to File -> Add Package Dependencies...
    2. Enter the URL: https://github.com/raymondjavaxx/SmoothGradient.git
    3. Set the dependency rule to from: "1.0.0".
    .package(url: "https://github.com/raymondjavaxx/SmoothGradient.git", from: "1.0.0")
  2. Use SmoothGradient on iOS 17+ or macOS 14+

    main

    For modern platforms (iOS 17+ and macOS 14+), use the SmoothLinearGradient view. This view provides a direct way to define a smooth gradient using a start color, end color, points, and an easing curve.

    Parameters:

    • from: The starting color.
    • to: The ending color.
    • startPoint: The starting position of the gradient.
    • endPoint: The ending position of the gradient.
    • curve: The easing function used to smooth the transition.
    import SmoothGradient
    
    struct ContentView: View {
        var body: some View {
            SmoothLinearGradient(
                from: .black,
                to: .white,
                startPoint: .top,
                endPoint: .bottom,
                curve: .easeInOut
            )
        }
    }
  3. Use SmoothGradient on Pre-iOS 17 / Pre-macOS 14

    main

    On older versions of iOS or macOS, you can apply smooth gradients to the standard SwiftUI LinearGradient by using the .smooth(from:to:curve:) modifier on a Gradient object.

    Usage: Pass the result of .smooth(from:to:curve:) to the gradient parameter of a LinearGradient view.

    import SmoothGradient
    
    struct ContentView: View {
        var body: some View {
            LinearGradient(
                gradient: .smooth(from: .black, to: .white, curve: .easeInOut),
                startPoint: .top,
                endPoint: .bottom
            )
        }
    }