42 lines
868 B
Swift
42 lines
868 B
Swift
import SwiftUI
|
|
import SFSafeSymbols
|
|
|
|
struct IconButton: View {
|
|
|
|
let action: () -> Void
|
|
|
|
let icon: SFSymbol
|
|
|
|
let iconSize: CGFloat
|
|
|
|
let buttonSize: CGFloat
|
|
|
|
private var padding: CGFloat {
|
|
(buttonSize - iconSize) / 2
|
|
}
|
|
|
|
private var cornerRadius: CGFloat {
|
|
buttonSize / 2
|
|
}
|
|
|
|
var body: some View {
|
|
Button(action: action) {
|
|
Image(systemSymbol: icon)
|
|
.resizable()
|
|
.frame(width: iconSize, height: iconSize)
|
|
.padding(padding)
|
|
.background(.thinMaterial)
|
|
.cornerRadius(cornerRadius)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct IconButton_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
IconButton(action: { },
|
|
icon: .xmark,
|
|
iconSize: 20,
|
|
buttonSize: 25)
|
|
}
|
|
}
|