Skip to content

Instantly share code, notes, and snippets.

@SoundBlaster
Created August 20, 2025 13:03
Show Gist options
  • Save SoundBlaster/4461ae1db3dfc148770f6393f7401d64 to your computer and use it in GitHub Desktop.
Save SoundBlaster/4461ae1db3dfc148770f6393f7401d64 to your computer and use it in GitHub Desktop.
SwiftUI Shape with Shaped Liquid Glass Effect
//
// 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