import SwiftUI
extension Link {
func pointingHandCursor() -> some View {
self.onHover { inside in
if inside {
NSCursor.pointingHand.set()
} else {
NSCursor.arrow.set()
}
}
}
}
In this code, we’ve created an extension for Link called pointingHandCursor()
that sets the cursor behavior. You can use this extension to apply the cursor change to any Link
in your SwiftUI views, making it more convenient to use in your app like below:
Link(destination: URL(string: "https://www.example.com")!) {
Text("Visit Example.com")
}
.pointingHandCursor() // Use the extension to set the cursor to a hand