Skip to content

Instantly share code, notes, and snippets.

@peterkos
Last active April 16, 2024 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkos/663736f925d420498f0e967f17513185 to your computer and use it in GitHub Desktop.
Save peterkos/663736f925d420498f0e967f17513185 to your computer and use it in GitHub Desktop.
DebugPosition
import SwiftUI
struct DebugPosition: ViewModifier {
var position: CGPoint
func body(content: Content) -> some View {
content
.overlay(alignment: .bottom) {
ZStack {
Text("(\(Int(position.x)), \(Int(position.y)))")
.multilineTextAlignment(.leading)
.foregroundStyle(.yellow)
.padding(.horizontal, 6)
.padding(.vertical, 3)
.background(
Capsule()
.foregroundStyle(.black)
)
.offset(y: -30)
Circle()
.stroke(.yellow, lineWidth: 3.0)
.frame(height: 10)
}
.position(
x: position.x,
y: position.y
)
}
}
}
extension View {
func debugPosition(_ position: CGPoint) -> some View {
modifier(
DebugPos(position: position)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment