Last active
December 30, 2024 20:48
-
-
Save Koshimizu-Takehito/55b83b21060a75d9c23049ea93a8266e to your computer and use it in GitHub Desktop.
SwiftUI Glow Text
This file contains hidden or 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
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