From 90bce31b43007c6ce8f3415c54f957a2524e8f4b Mon Sep 17 00:00:00 2001 From: QuantumThom <56136360+QuantumThom@users.noreply.github.com> Date: Sat, 5 Oct 2019 00:10:00 -0500 Subject: [PATCH] Update Calculator.swift Changed layout of calculator UI, and added Modulus function (removed some others) --- .../Calculator/Calculator/Calculator.swift | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Other Projects/Calculator/Calculator/Calculator/Calculator.swift b/Other Projects/Calculator/Calculator/Calculator/Calculator.swift index 378bd75..32b95d6 100755 --- a/Other Projects/Calculator/Calculator/Calculator/Calculator.swift +++ b/Other Projects/Calculator/Calculator/Calculator/Calculator.swift @@ -13,11 +13,11 @@ struct Calculator: View { @State private var display = "0" @State private var brain = CalculatorBrain() - let data = [["+", "−", "÷", "×"], - ["π", "7", "8", "9"], - ["√", "4", "5", "6"], - ["cos", "1", "2", "3"], - ["±", ".", "0", "="]] + let data = [["AC","±", "%", "÷"], + ["7", "8", "9","×"], + ["4", "5", "6","-"], + ["1", "2", "3", "+"], + ["0", ".", "="]] var body: some View { let margin: CGFloat = 10 @@ -25,10 +25,12 @@ struct Calculator: View { HStack { Spacer() - Text(display) - .foregroundColor(Color(red: 231 / 255.0, green: 76 / 255.0, blue: 60 / 255.0)) - .font(.largeTitle) - .frame(height: 50) + Button(action: {}){ + Text(display) + .foregroundColor(Color(red: 231 / 255.0, green: 76 / 255.0, blue: 60 / 255.0)) + .font(.largeTitle) + .frame(height: 120) + }.padding(.all) } .padding(margin) @@ -36,6 +38,7 @@ struct Calculator: View { ForEach(data, id: \.description) { items in HStack(alignment: .center, spacing: margin) { ForEach(items, id: \.description) { item in + Button(action: {}){ Text(item) .font(.title) .bold() @@ -45,6 +48,8 @@ struct Calculator: View { .onTapGesture { self.touchAction(item) } + + } } } } @@ -60,7 +65,9 @@ struct Calculator: View { } else { performOperation(symbol) } + } + private func touchDigit(_ digit: String) { print(#function)