Skip to content

Instantly share code, notes, and snippets.

@Koshimizu-Takehito
Created July 29, 2024 13:37
Show Gist options
  • Save Koshimizu-Takehito/55b83b21060a75d9c23049ea93a8266e to your computer and use it in GitHub Desktop.
Save Koshimizu-Takehito/55b83b21060a75d9c23049ea93a8266e to your computer and use it in GitHub Desktop.
SwiftUI Glow Text
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var scheme
private let date = Date()
private let colors = [Color.green, .pink, .blue, .orange, .purple]
private let titles = ["NEON", "GLOW", "LIGHT", "SHINE", "BRIGHT"]
var body: some View {
TimelineView(.animation) { context in
let index = (Int(context.date.timeIntervalSince(date)) + 1) % colors.count
let color = colors[index]
Text(titles[index])
.contentTransition(.numericText(countsDown: true))
.animation(.default, value: index)
.font(.system(size: 70, weight: .thin))
.frame(width: 250)
.shadow(color: color, radius: 5)
.shadow(color: color, radius: 50)
.shadow(color: color, radius: 100)
.shadow(color: color, radius: 150)
.shadow(color: color, radius: 200)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.foregroundStyle(scheme == .light ? AnyShapeStyle(.background) : AnyShapeStyle(.foreground))
.background(scheme == .light ? AnyShapeStyle(.foreground) : AnyShapeStyle(.background))
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment