Created
July 1, 2020 15:56
-
-
Save smartvipere75/394851cb127a0f3a4116073af51d77bb to your computer and use it in GitHub Desktop.
Keypad in SwiftUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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