I am currently making an app that takes in three user inputs for a red, green, and blue color value between 0 and 255 through separate TextField
views. Right now, the user can input the values fine but there is no way of tabbing out of the keyboards. I understand there are two main ways to go about this. The first is adding a return button to the keyboard and the second is exiting out through a tap gesture.
I am fairly new to SwiftUI and I keep seeing online that the best solution is to override the viewDidLoad function and set a tap gesture in there. I am honestly not sure what the viewDidLoad
function is and I am still very confused after researching it. At the moment, I am also not very familiar with UIViewController
s.
Is there an easier way to solve my issue or will I have to use a UIViewController
and override the viewDidLoad
function?
enter code here
VStack {
TextField("255", text: $redC) { editing in
isEditing = editing
redV = (redC as NSString).doubleValue
} onCommit: {
redV = (redC as NSString).doubleValue
}
TextField("255", text: $greenC) { editing in
isEditing = editing
greenV = (greenC as NSString).doubleValue
} onCommit: {
greenV = (greenC as NSString).doubleValue
}
TextField("255", text: $blueC) { editing in
isEditing = editing
blueV = (blueC as NSString).doubleValue
} onCommit: {
blueV = (blueC as NSString).doubleValue
}
}
.multilineTextAlignment(.center)
.keyboardType(.numberPad)