Open rolson opened 2 months ago
Another way is to add a private SwiftUI view to use the native close button in UIKit.
Field Maps uses it, and a condensed version looks like
struct CloseButton: UIViewRepresentable {
private let action: () -> Void
init(action: @escaping () -> Void) { self.action = action }
func makeUIView(context: Context) -> UIButton {
let button = UIButton(type: .close, primaryAction: UIAction { _ in action() })
for axis in [NSLayoutConstraint.Axis.horizontal, .vertical] {
button.setContentCompressionResistancePriority(.required, for: axis)
button.setContentHuggingPriority(.required, for: axis)
}
return button
}
func updateUIView(_ uiView: UIButton, context: Context) {}
}
The close button in the floor filter looks like this:
However, with Apple's own apps, I see it often like this:
What I've found works well for that look is this code:
And actually, I think we are already using that in the world scale scene view's calibration view.
You can actually create a predefined dismiss button with something like this: