Update Calculator.swift

Changed layout of calculator UI, and added Modulus function (removed some others)
This commit is contained in:
QuantumThom
2019-10-05 00:10:00 -05:00
committed by GitHub
parent e7ea70c42f
commit 90bce31b43

View File

@@ -13,11 +13,11 @@ struct Calculator: View {
@State private var display = "0" @State private var display = "0"
@State private var brain = CalculatorBrain() @State private var brain = CalculatorBrain()
let data = [["+", "", "÷", "×"], let data = [["AC","±", "%", "÷"],
["π", "7", "8", "9"], ["7", "8", "9","×"],
["", "4", "5", "6"], ["4", "5", "6","-"],
["cos", "1", "2", "3"], ["1", "2", "3", "+"],
["±", ".", "0", "="]] ["0", ".", "="]]
var body: some View { var body: some View {
let margin: CGFloat = 10 let margin: CGFloat = 10
@@ -25,10 +25,12 @@ struct Calculator: View {
HStack { HStack {
Spacer() Spacer()
Text(display) Button(action: {}){
.foregroundColor(Color(red: 231 / 255.0, green: 76 / 255.0, blue: 60 / 255.0)) Text(display)
.font(.largeTitle) .foregroundColor(Color(red: 231 / 255.0, green: 76 / 255.0, blue: 60 / 255.0))
.frame(height: 50) .font(.largeTitle)
.frame(height: 120)
}.padding(.all)
} }
.padding(margin) .padding(margin)
@@ -36,6 +38,7 @@ struct Calculator: View {
ForEach(data, id: \.description) { items in ForEach(data, id: \.description) { items in
HStack(alignment: .center, spacing: margin) { HStack(alignment: .center, spacing: margin) {
ForEach(items, id: \.description) { item in ForEach(items, id: \.description) { item in
Button(action: {}){
Text(item) Text(item)
.font(.title) .font(.title)
.bold() .bold()
@@ -45,6 +48,8 @@ struct Calculator: View {
.onTapGesture { .onTapGesture {
self.touchAction(item) self.touchAction(item)
} }
}
} }
} }
} }
@@ -60,7 +65,9 @@ struct Calculator: View {
} else { } else {
performOperation(symbol) performOperation(symbol)
} }
} }
private func touchDigit(_ digit: String) { private func touchDigit(_ digit: String) {
print(#function) print(#function)