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