Post

Replies

Boosts

Views

Activity

Reply to Buttons To Control Gradients
This is the code so far. Some lines may seem irrelevant, but thats just because I'm planning on doing something with them later on. Staying on topic, what I want to do is have a button that, when pressed, changes the gradient from a set list of gradients. For example, the current result looks like this: And then when the button is pressed, I want it to look like this with a smooth transition:
Nov ’21
Reply to Getting The Value From a Picker
Yeah, here it is import SwiftUI struct ContentView: View {   @State private var checkoutAmount=""   @State private var numberOfPeople=1   @State private var tipPercentage=1   let tipPercentages=[10,15,20,25,0]   var totalPerPerson: Double {     let peopleCount=Double(numberOfPeople+1)           let tipSelection=Double(tipPercentages[tipPercentage])     let orderAmount=Double(checkoutAmount) ?? 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:$checkoutAmount)             .keyboardType(.decimalPad)           Picker("Number of People:", selection: $numberOfPeople){             ForEach(1..101){               Text("\($0) people")             }           }         }                   Section(header: Text("Tip Percentage:")){                       Picker("Tip Percentage:", selection: $tipPercentage) {             ForEach(0..tipPercentages.count) {               Text("\(self.tipPercentages[$0])%")             }                         }           .pickerStyle(SegmentedPickerStyle())         }         Section{           Text("$\(totalPerPerson,specifier: "%.2f")")         }       }       .navigationBarTitle("WeSplit", displayMode: .inline)     }         } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } It's just a simple project that takes a bill, gets the number of people, the tip, and then calculates the final price each person has to pay. This code works, but that's only because I added a +1 to the numberOfPeople variable since it took the index instead of the value, but I was just wondering if there was a way to get the value instead. The Italicized and bolded part is the code that I am referencing
Apr ’21