Skip to content

Instantly share code, notes, and snippets.

@smartvipere75
Created July 1, 2020 15:56
Show Gist options
  • Select an option

  • Save smartvipere75/394851cb127a0f3a4116073af51d77bb to your computer and use it in GitHub Desktop.

Select an option

Save smartvipere75/394851cb127a0f3a4116073af51d77bb to your computer and use it in GitHub Desktop.
Keypad in SwiftUI.
import SwiftUI
struct KeypadCell: View {
let key: String
var body: some View {
ZStack {
Color.primary.opacity(0.1)
.cornerRadius(12)
if key == "<" {
Image(systemName: "delete.left.fill")
.font(.title2)
.padding()
} else {
Text(key)
.font(.title2)
.fontWeight(.bold)
.padding()
}
}
}
}
struct Keypad: View {
private let keys: [String] = ["1","2","3","4","5","6","7","8","9",".","0","<"]
var body: some View {
LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3)) {
ForEach(keys, id: \.self) { key in
Button(action: {
print("Tapped on \(key)")
}) {
KeypadCell(key: key)
}.buttonStyle(PlainButtonStyle())
}
}.frame(maxWidth: 320)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment