0
我想改变textColor.Though我正确地输入到文本字段中的数字,它只适用于“其他”条件,但不适用于'如果'。这是我的代码。更改texttextcolor为UITextField
任何人都可以解决此问题。由于
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()
}
}
'如果fieldOne.text == “1”' –
@Pyro他有一个出口每个领域为什么他需要标记他们?正如OP所述“当我在文本框中正确输入数字时” –
@LeoDabus非常感谢。有效。 – Terril320