mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-17 06:19:48 +02:00
Merge pull request #21 from QuantumThom/patch-1
Update Calculator.swift
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user