Skip to content

Instantly share code, notes, and snippets.

@denisenepraunig
Created November 26, 2023 18:59
Show Gist options
  • Save denisenepraunig/a9c5f0e7b0c9cf38c55b88e9aae97d12 to your computer and use it in GitHub Desktop.
Save denisenepraunig/a9c5f0e7b0c9cf38c55b88e9aae97d12 to your computer and use it in GitHub Desktop.
SwiftUI Card with glowing edges inside app with subtle blur background
//
// ContentView.swift
// GradientCard
//
// Created by Denise Nepraunig on 26.11.23.
//
import SwiftUI
struct GradientLine: View {
var body: some View {
RoundedRectangle(cornerRadius: 0, style: .continuous)
.fill(
LinearGradient(
gradient: Gradient(stops: [
.init(color: .clear, location: 0.0),
.init(color: .clear, location: 0.25),
.init(color: .blue, location: 0.5),
.init(color: .clear, location: 0.75),
]),
startPoint: .leading,
endPoint: .trailing
)
)
.blur(radius: 0.5)
.frame(height: 1)
}
}
struct GradientShape: View {
var body: some View {
VStack {
GradientLine()
Spacer()
GradientLine()
}
}
}
let text = """
Hello World!
I tried to create a gradient UI
with some fancy glowing edges.
"""
struct ContentView: View {
var body: some View {
ZStack {
Color.black.opacity(0.7).ignoresSafeArea(edges: .all)
// background rectangle with sligth blur
Rectangle()
.fill(Color.blue.opacity(0.15))
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
.blur(radius: 200) // Increase or decrease radius for desired blur effect
Text(text)
.font(.title)
.padding(36)
.overlay(content: {
ZStack {
GradientShape()
RoundedRectangle(cornerRadius: 10)
.stroke(.quaternary, lineWidth: 1)
}
})
.background {
Color.black.opacity(0.3)
}
.clipShape(RoundedRectangle(cornerRadius: 10.0))
}
}
}
#Preview {
ContentView()
}
@denisenepraunig
Copy link
Author

denisenepraunig commented Nov 26, 2023

Screenshot:

Screenshot 2023-11-26 at 19 57 55

@denisenepraunig
Copy link
Author

denisenepraunig commented Nov 26, 2023

Inspiration:

https://sigmahq.io

Screenshot 2023-11-26 at 18 20 49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment