UITextField.textColor在UITextField获得焦点之前不会被调用

时间:2017-08-25 08:33:17

标签: swift3 xcode8 swift4 xcode9

有人可以解释一下如何/何时为UITextField调用.textColor?

XCode9,Swift 4

请考虑以下代码:

import UIKit

class TestViewController: UIViewController {

@IBOutlet weak var txt1: UITextField!
@IBOutlet weak var txt2: UITextField!

@IBAction func btnaction(_ sender: UIButton) {
    txt1.textColor=UIColor.red
    txt1.backgroundColor=UIColor.green.withAlphaComponent(0.5)
    txt2.textColor=UIColor.red
    txt2.backgroundColor=UIColor.green.withAlphaComponent(0.5)
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

一切都是连通的。当您运行它并单击按钮时,只会立即设置backgroundColor。 .textColor保持不变。只有当文本字段获得焦点时,才会改变.textColor。

这是正确的行为还是错误?

感谢您的评论。

我在XCode 8,Swift 3中尝试了相同的代码并且它工作正常,所以我相信它可能是一个错误。

0 个答案:

没有答案
相关问题