Skip to content

Instantly share code, notes, and snippets.

@hasanalisiseci
Created December 13, 2023 11:52
Show Gist options
  • Save hasanalisiseci/01ce9c4716c783dfb7e9f1e579a320a5 to your computer and use it in GitHub Desktop.
Save hasanalisiseci/01ce9c4716c783dfb7e9f1e579a320a5 to your computer and use it in GitHub Desktop.
//
// LinearGradientBG.swift
//
//
// Created by Hasan Ali Şişeci on 13.12.2023.
//
import SwiftUI
public struct LinearGradientBackground: ViewModifier {
let gradient: LinearGradient
let opacity: Double
public func body(content: Content) -> some View {
content.background(
gradient
.opacity(opacity)
.edgesIgnoringSafeArea(.all)
)
}
}
extension View {
/// Generic background function for scenes
func linearGradientBackground(_ gradient: LinearGradient = LinearGradient(colors: [.red, .pink], startPoint: .top, endPoint: .bottom), _ opacity: Double = 1.0) -> some View {
self
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
.modifier(LinearGradientBackground(gradient: gradient, opacity: opacity))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment