Alright it seems to work but when I get to get the the third textfield it seems the code seems to stop and it does not show anything.
Post
Replies
Boosts
Views
Activity
It still does not seem to work.
OtWidth.constant is the width of the shape it's not constant which is ironic. I want when each of the sliders becomes 0 to not show anything.
I have to convert it my textFields to NSObjects and it does not work in the end. The check marks are the check followed by a number and the xs are wrong followed by a number.
I am trying to allow the textField I have to accept an Int that moves a slider, I can get it to work by commenting out my function that only allows values from 10 to 90.
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
// Make sure the user entered a number
let num = Double(textField.text!)
if num! < 10 {
textField.text = "10%"
} else if num! > 90 {
textField.text = "90%"
} else if num! >= 10 || num! <= 90 {
textField.text = String(Int(num!)) + "%"
}
//print(num!)
return true
}
It says found nil while unwrapping an optional value. slider.value = Float(textNum!), the textNum is nil but when I print text it's an optional value. let text = textField.text
Thats the thing I'm struggling with. I modified the function so it can be better understood. widthPer is the textField I have selected to change my slider value when a value is entered but it does not work and the textField returns nil.
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
let text = textField.text
let textNum = Int(text!)
if widthPer.text == text {
slider.value = Float(textNum!)
}
return true
}
I know there is a lot of details but I think if I got the slider at the position of what the text input is then I could solve the rest on my own. slider.value = Float(textNum!)
Okay I see what you mean but I have an issue implementing it for two textfields. It says my text value is nil and it does not move the slider.
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
let text = textField.text
let textNum = Int(text!)
/*when you enter a value it will affect, the slider and squareOne width value will change and squareTwo width will change */
if widthPer.text == text {
squareOneWidth.constant = CGFloat(textNum!) * 2
slider.value = Float(textNum!)
calPercentage()
calPercentageTwo()
/*when you enter a value it will affect, the sliderHeight and squareOne height will change and squareTwo height will change */
} else if heightPer.text == text {
calPercentage()
calPercentageTwo()
}
print("\(text)")
return true
}
I mean lets say I have another textField that I want to control a different slider is there another function other then textFieldShouldReturn()?
Does it have to be TextFieldShouldReturn can there be another function if I want to add another textfield?
Ignore this thread
Thank you for the help I just needed the options: [.repeat, .autoreverse] and I got rid of the next handler for the continuous repeat.
I always try a potential solution and it does not work because I want it to repeat indefinitely.
The thing is I want the decrease to repeat and be smooth.