[ad_1]
Hello and sorry if its a dumb query.
I’ve been following HackingWithSwift SwiftUI tutorial day 19(hyperlink)
however I’m going through an issue. I attempted to make use of .focus() modifier and a boolean to deal with a button and conceal my keyboard when person press executed. At any time when I’m attempting to cover my keyboard I’ve 2 ‘Completed’ buttons though I simply added one to my UI and even once I take away that one button it wont present no “Completed” button in any respect and I am unable to disguise my keyboard.
Observe: I attempted it on Preview and iPhone Simulator however not on a bodily system.
I added a screenshot and code as properly.
Right here is my code:
// ContentView.swift
// WeSplit
import SwiftUI
struct ContentView: View {
@State non-public var checkAmount = 0.0
@State non-public var numberOfPeople = 2
@State non-public var tipPercentage = 20
@FocusState non-public var amountIsFocused: Bool
let tipPercentages = [10, 15, 20, 25, 0]
//For Whole price + tip
var grandTotal: Double{
let tipSelection = Double(tipPercentage)
let tipValue = checkAmount / 100 * tipSelection
let grandTotal = checkAmount + tipValue
return grandTotal
}
//For particular person share
var totalPerPerson: Double{
let peopleCount = Double(numberOfPeople + 2)
let amountPerPerson = grandTotal / peopleCount
return amountPerPerson
}
var physique: some View {
NavigationView {
Type{
Part{
TextField("Quantity: ", worth: $checkAmount, format: .forex(code: Locale.present.currencyCode ?? "USD"))
.keyboardType(.decimalPad)
.targeted($amountIsFocused)
Picker("Variety of individuals", choice: $numberOfPeople){
ForEach(2..<100){
Textual content("($0) individuals")
}
}
}
Part{
Picker("Tip Proportion", choice: $tipPercentage){
ForEach(tipPercentages, id:.self){
Textual content($0, format: .p.c)
}
}.pickerStyle(.segmented)
}header: {
Textual content("How a lot tip do you wish to go away?")
}
//Grand Whole
Part{
Textual content(grandTotal, format:.forex(code: Locale.present.currencyCode ?? "USD"))
}header: {
Textual content("Whole Price + Tip")
}
//Exhibiting every particular person's share
Part{
Textual content(totalPerPerson, format: .forex(code: Locale.present.currencyCode ?? "USD"))
}header: {
Textual content("Quantity Per Particular person")
}.navigationTitle("WeSplit")
.toolbar(){
ToolbarItemGroup(placement: .keyboard){
Button("Completed"){
amountIsFocused = false
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Right here is the screenshot:
[ad_2]

