Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var buttonsText = ["AC", "±", "%", "÷",
- "7", "8", "9", "x",
- "4", "5", "6", "-",
- "1", "2", "3", "+",
- "0", "00", ".", "="]
- @State var screenValue = "0"
- var calculator = Calculator()
- var body: some View {
- VStack { // Vertical Stack İçerisindeki elemanları yatay olarak alt alta ekler
- Spacer()
- VStack(alignment: .trailing) {
- Text(screenValue) // Hesap Makinemizin sonuç değeri.
- .bold()
- .font(.largeTitle)
- .padding()
- .gesture(
- DragGesture(minimumDistance: 50)
- .onEnded { _ in
- self.screenValue = self.calculator.deleteLast()
- }
- )
- Divider()
- }
- ForEach((0...4)) { firstIndex in
- HStack(alignment: .bottom) // Horizontal Stack İçerisindeki elemanları dikey olarak yan yana sıralar.
- {
- ForEach((0...3)) { secondIndex in
- ZStack { // Z Satck içerisindeki elemanlar üst üste gelecek şekilde yerleştirir.
- Circle()
- .frame(width: 75, height: 75, alignment: .center)
- .foregroundColor(self.getColor(firstIndex: firstIndex, secondIndex: secondIndex))
- .padding(10)
- .tapAction {
- self.touchButton(button: self.buttonsText[(firstIndex * 4) + secondIndex])
- }
- Text(self.buttonsText[(firstIndex * 4) + secondIndex])
- // .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
- .color(.white)
- .bold()
- .font(.title)
- .tapAction { // :(
- self.touchButton(button: self.buttonsText[(firstIndex * 4) + secondIndex])
- }
- }
- }
- }
- }
- }
- }
- func getColor(firstIndex: Int, secondIndex: Int) -> Color
- {
- if firstIndex == 0 && secondIndex != 3
- { return .init(red: 0.65, green: 0.65, blue: 0.65) }
- if secondIndex == 3
- { return .orange }
- return .init(red: 0.20, green: 0.20, blue: 0.20)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement