-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentView.swift
More file actions
71 lines (54 loc) · 1.91 KB
/
ContentView.swift
File metadata and controls
71 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//4os
import SwiftUI
struct ContentView: View {
@State private var checkAmount = ""
@State private var numberOfPeople = 2
@State private var tipPercantage = 2
let tipPercentages = [10, 15, 20, 25, 0]
var totalPerson: Double {
let peopleCount = Double(numberOfPeople + 2)
let tipSelection = Double(tipPercentages[tipPercantage])
let orderAmount = Double(checkAmount) ?? 0
let tipValue = orderAmount / 100 * tipSelection
let grandTotal = orderAmount + tipValue
let amountPerPerson = grandTotal / peopleCount
return amountPerPerson
}
var body: some View {
NavigationView{
Form {
Section {
TextField("Amount", text: $checkAmount)
.keyboardType(.decimalPad)
Picker("Number of people" , selection: $numberOfPeople) {
ForEach(2 ..< 100){
Text("\($0) people")
}
}
}
Section {
Picker("Tip Percantage", selection: $tipPercantage) {
ForEach(0 ..< tipPercentages.count) {
Text("\(self.tipPercentages[$0])%")
}
}.pickerStyle(.segmented)
} header: {
Text("How much tip do you want to leave??")
}
Section {
Text("$\(totalPerson, specifier: "%.2f")")
}
Section{
Text("This is my first SwiftUI App. GitHub/4os")
}
.navigationTitle("Hesabını Paylaş ")
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}