Created
August 20, 2025 13:03
-
-
Save SoundBlaster/4461ae1db3dfc148770f6393f7401d64 to your computer and use it in GitHub Desktop.
SwiftUI Shape with Shaped Liquid Glass Effect
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
// | |
// ContentView.swift | |
// GlassOnAWater | |
// | |
// Created by Merkushev Egor on 20.08.2025. | |
// | |
import SwiftUI | |
struct DonutShape: Shape { | |
var holeRadiusFraction: CGFloat = 0.75 | |
func path(in rect: CGRect) -> Path { | |
var path = Path() | |
let outerRadius = min(rect.width, rect.height) / 2.0 | |
let innerRadius = outerRadius * holeRadiusFraction | |
let center = CGPoint(x: rect.midX, y: rect.midY) | |
path.addArc(center: center, radius: outerRadius, startAngle: .degrees(0), endAngle: .degrees(360), clockwise: false) | |
path.addArc(center: center, radius: innerRadius, startAngle: .degrees(360), endAngle: .degrees(0), clockwise: true) | |
return path | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
ZStack { | |
Image("test") | |
.resizable() | |
.scaledToFit() | |
DonutShape(holeRadiusFraction: 0.5) | |
.glassEffect(.regular.tint(.blue.opacity(0.75)), | |
in: DonutShape(holeRadiusFraction: 0.5)) | |
.frame(width: 300, height: 300) | |
.padding() | |
} | |
.ignoresSafeArea() | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment