-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageButton.swift
48 lines (43 loc) · 1.33 KB
/
ImageButton.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
A SwiftUI view used by the app's buttons.
*/
import OSLog
import SwiftUI
/// A simple button with an image. This is used in the piece shelf.
public struct ImageButton: View {
var title: String
var imageName: String
var imageBundle: Bundle? = nil
var buttonAction: (ImageButton) -> Void
// Use this to pass information to the button's action closure.
var context = [String: Any]()
@Environment(\.isEnabled) var isEnabled
public var body: some View {
Button {
buttonAction(self)
} label: {
VStack {
Image(imageName, bundle: imageBundle)
.resizable()
.scaledToFit()
.opacity(isEnabled ? 1.0 : 0.5)
Text(title)
.font(.system(size: 12))
.lineLimit(1)
.padding(.bottom, 10)
}
}
.buttonStyle(.borderless)
.buttonBorderShape(.roundedRectangle)
.accessibilityElement()
}
}
#Preview {
ImageButton(title: "Simple Ramp", imageName: "slide_01_metal") { button in
os_log("Pressed")
}
.glassBackgroundEffect(in: .rect(cornerRadius: 14))
.frame(width: 86, height: 86)
}