Reputation: 113
I have been trying to animate the textfield background color from default color to cyan(fade-in effect), I searched a lot but I am unable to do it.
this is the textfield code
physics.frame = CGRect(x: 100, y: 863, width: 60, height: 30)
physics.addTarget(self, action: #selector(stringValidation), for: .editingChanged)
physics.addTarget(self, action: #selector(editValidation), for: .editingChanged)
physics.keyboardType = .numberPad
physics.borderStyle = .roundedRect
scroller1.addSubview(physics)
P.S. I have already declared physics variable globally as UITextField and I am using Swift 4
Your time and help will be highly appreciated!
Upvotes: 0
Views: 177
Reputation: 100523
You can try
self.physics.backgroundColor = .red
UIView.animate(withDuration:0.5) {
self.physics.backgroundColor = .cyan
}
Upvotes: 1