2017-03-15 9 views
0

を使用してラベルの背景色をアニメーション化することができ、私は完全にこのコードは、アニメーションの背景色があります。はどのように私はスウィフト

UIView.animate(withDuration: 2, delay: 0.0, options:[UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse], animations: { 
     self.view.backgroundColor = UIColor(red: 0/255, green: 185/255, blue: 215/255, alpha: 1.0) 
     self.view.backgroundColor = UIColor(red: 0/255, green: 78/255, blue: 215/255, alpha: 1.0) 
     self.view.backgroundColor = UIColor(red: 0/255, green: 215/255, blue: 138/255, alpha: 1.0) 
}, completion: nil) 

をしかし、私は、ラベルの背景色をアニメーション化するためにそれを使用しようとしましたが、濃い色で、それが動作しませんでした:

UIView.animate(withDuration: 2, delay: 0.0, options:[UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse], animations: { 
     self.topBar.backgroundColor = UIColor(red: 0/255, green: 159/255, blue: 184/255, alpha: 1.0) 
     self.topBar.backgroundColor = UIColor(red: 0/255, green: 67/255, blue: 184/255, alpha: 1.0) 
     self.topBar.backgroundColor = UIColor(red: 0/255, green: 184/255, blue: 117/255, alpha: 1.0) 
}, completion: nil) 

は、何か問題があるのか​​、私はラベルの背景色をアニメーション化するために何ができるのでしょうか?

+1

可能な複製[UILabelの背景色をアニメーション化するには?](http://stackoverflow.com/質問/ 3762561/how-to-animate-the-background-of-a-uilabel) –

答えて

2

はlayer.backgroundColorをアニメーション化しようと代わりのbackgroundColor

このコードは私の作品

UIView.animate(withDuration: 2, delay: 0.0, options:[UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse], animations: { 
     self.label.layer.backgroundColor = UIColor(red: 0/255, green: 185/255, blue: 215/255, alpha: 1.0).cgColor 
     self.label.layer.backgroundColor = UIColor(red: 0/255, green: 78/255, blue: 215/255, alpha: 1.0).cgColor 
     self.label.layer.backgroundColor = UIColor(red: 0/255, green: 215/255, blue: 138/255, alpha: 1.0).cgColor 
    }, completion: nil)