feat: add icon buttons
This commit is contained in:
parent
baed7cf0aa
commit
71a7116365
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// SwiftUIView.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Yhanco Grey Esteban on 6/5/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct Icon: View {
|
||||||
|
let name: String
|
||||||
|
|
||||||
|
/// Creates a view with system icon that is resizable
|
||||||
|
/// - Parameter name: name of system icon
|
||||||
|
init(_ name: String) {
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Image(systemName: name)
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Icon_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
Icon("checkmark.circle.fill")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
//
|
||||||
|
// SwiftUIView.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Yhanco Grey Esteban on 6/5/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct IconButton: View {
|
||||||
|
let name: String
|
||||||
|
let action: () -> Void
|
||||||
|
|
||||||
|
|
||||||
|
/// Creates a button using a system icon
|
||||||
|
/// - Parameters:
|
||||||
|
/// - name: system icon name
|
||||||
|
/// - action: The action to perform when the user triggers the button.
|
||||||
|
init(_ name: String, action: @escaping () -> Void) {
|
||||||
|
self.name = name
|
||||||
|
self.action = action
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Button {
|
||||||
|
action()
|
||||||
|
} label: {
|
||||||
|
Icon(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SwiftUIView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
IconButton("checkmark.circle.fill") {
|
||||||
|
print("I did something")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue