mercredi 30 mars 2016

Text color not changing correctly for textfields

When I enter the numbers correctly into the textfields, why does the text color only work for the "else" statement option and not for the "if" option ?

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var questionOne: UILabel!
@IBOutlet weak var fieldOne: UITextField! // textFields should be set as labels

@IBOutlet weak var questionTwo: UILabel!
@IBOutlet weak var fieldTwo: UITextField!

@IBOutlet weak var questionThree: UILabel!
@IBOutlet weak var fieldThree: UITextField!


@IBOutlet weak var questionFour: UILabel!
@IBOutlet weak var fieldFour: UITextField!


@IBAction func submitButton(sender: UIButton) {
    fieldOneColorChange()
    fieldTwoColorChange()
    fieldThreeColorChange()
    fieldFourColorChange()
}

@IBAction func resetButton(sender: UIButton) {
}

// Text color changes

func fieldOneColorChange() {
    if fieldOne == 1 {
        questionOne.textColor = UIColor.redColor()
    } else {
        questionOne.textColor = UIColor.blueColor()

    } 
}

func fieldTwoColorChange() {
    if fieldTwo == 2 {
        questionTwo.textColor = UIColor.brownColor()
    } else {
       questionTwo.textColor = UIColor.redColor()

    } 
}

func fieldThreeColorChange(){
    if fieldThree == 3 {
        questionThree.textColor = UIColor.blueColor()
    } else {
        questionThree.textColor = UIColor.purpleColor()
    }
}

func fieldFourColorChange(){
    if fieldFour == 4 {
        questionFour.textColor = UIColor.blueColor()
    } else {
        questionFour.textColor = UIColor.redColor()

    } 
}

Aucun commentaire:

Enregistrer un commentaire