Created
December 13, 2023 11:52
-
-
Save hasanalisiseci/01ce9c4716c783dfb7e9f1e579a320a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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