import SwiftUI
struct GlassmorphismTutorialBootCamp: View {
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: [Color.white, Color.white.opacity(0.0)]), startPoint: .top, endPoint: .bottom)
LinearGradient(gradient: Gradient(colors: [Color.blue.opacity(0.6), Color.purple.opacity(0.3)]), startPoint: .topLeading, endPoint: .bottomTrailing)
// Bottom Layer View -> Opacity
// Background -> Make CardView popable
popUpView
}
}
}
}
extension ContentView {
private var popUpView: some View {
ZStack(alignment: .topLeading) {
Color.white.opacity(0.5)
.frame(width: 300, height: 400)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
.blur(radius: 1)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 10)
// opacity + blur -> background color
VStack(alignment: .leading, spacing: 16) {
Text("Glassmorphism")
.font(.system(size: 24, weight: .bold, design: .rounded))
Text("Transparent and Beautiful".uppercased())
.font(.caption)
Text("You can see through this card view")
.font(.footnote)
}
.padding()
.frame(width: 300, height: 400)
.foregroundColor(Color.black.opacity(0.8))
}
}
}
opacity
를 통해 백그라운드를 비춰보이는 것import SwiftUI
struct GlassmorphismTutorialBootCamp: View {
@State private var isAnimating: Bool = false
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: [Color.white, Color.white.opacity(0.0)]), startPoint: .top, endPoint: .bottom)
LinearGradient(gradient: Gradient(colors: [Color.blue.opacity(0.6), Color.purple.opacity(0.3)]), startPoint: .topLeading, endPoint: .bottomTrailing)
// Background -> Make CardView popable
ZStack {
Circle()
.frame(width: 400, height: 400)
.offset(x: 150, y: -200)
.foregroundColor(Color.purple.opacity(0.6))
.blur(radius: 8)
.scaleEffect(isAnimating ? 0.8 : 1)
Circle()
.frame(width: 400, height: 400)
.offset(x: -100, y: -125)
.foregroundColor(Color.blue.opacity(0.4))
.blur(radius: 8)
.scaleEffect(isAnimating ? 0.8 : 1)
Circle()
.frame(width: 400, height: 400)
.offset(x: 50, y: 150)
.foregroundColor(Color.cyan.opacity(0.4))
.blur(radius: 8)
.scaleEffect(isAnimating ? 0.8 : 1)
popUpView
}
}
.onReceive(timer, perform: { _ in
withAnimation(.default) {
isAnimating.toggle()
}
})
.ignoresSafeArea()
}
}
extension ContentView {
private var popUpView: some View {
ZStack(alignment: .topLeading) {
Color.white.opacity(0.5)
.frame(width: 300, height: 400)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
.blur(radius: 1)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 10)
VStack(alignment: .leading, spacing: 16) {
Text("Glassmorphism")
.font(.system(size: 24, weight: .bold, design: .rounded))
Text("Transparent and Beautiful".uppercased())
.font(.caption)
Text("You can see through this card view")
.font(.footnote)
}
.padding()
.frame(width: 300, height: 400)
.foregroundColor(Color.black.opacity(0.8))
}
}
}
튜토리얼 난이도의 글래스모피즘에 관해 공부해 보았다. SwiftUI가 제공하는 매우 간단한 ZStack, 도형 및 색깔 함수를 통해 쉽게 구현할 수 있다는 게 장점.