Swift3 UITextField.textColor在UITextField获得焦点之前不调用
有人能解释一下UITextField是如何/何时调用.textColor的吗 XCode9,swift4 考虑以下代码:Swift3 UITextField.textColor在UITextField获得焦点之前不调用,swift3,xcode8,swift4,xcode9,Swift3,Xcode8,Swift4,Xcode9,有人能解释一下UITextField是如何/何时调用.textColor的吗 XCode9,swift4 考虑以下代码: import UIKit class TestViewController: UIViewController { @IBOutlet weak var txt1: UITextField! @IBOutlet weak var txt2: UITextField! @IBAction func btnaction(_ sender: UIButton) { t
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.
}
}
一切都是相连的。当您运行它并单击按钮时,只有背景颜色会立即设置。.textColor保持不变。仅当文本字段获得焦点时,.textColor才会更改
这是正确的行为还是错误
谢谢你的评论
我在XCode 8、Swift 3中尝试了相同的代码,效果很好,所以我认为这可能是一个bug。这是一个奇怪的行为。这可能是因为XCODE仍处于测试版。(人们就是这么想的)这是一种奇怪的行为。这可能是因为XCODE仍处于测试版。(这就是我的想法)