Created
February 27, 2020 00:27
-
-
Save dnedrow/20f1a5e40fa51c3cabf4d7b6819486fa to your computer and use it in GitHub Desktop.
Provides a shimmer animation for labels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Shimmer.swift | |
| // | |
| // Created by Romanov, Radu on 6/12/19. | |
| // | |
| import Foundation | |
| extension UIView { | |
| func startShimmerAnimation() { | |
| let gradientLayer = CALayer(layer: layer) | |
| gradientLayer.backgroundColor = UIColor.white.cgColor | |
| gradientLayer.frame = CGRect(x: 0, y: 0, width: bounds.width / 3, height: bounds.height) | |
| gradientLayer.opacity = 0.18 | |
| layer.addSublayer(gradientLayer) | |
| let animation = CABasicAnimation(keyPath: "transform.translation.x") | |
| animation.duration = 1.0 | |
| animation.fromValue = -frame.size.width | |
| animation.toValue = frame.size.width | |
| animation.repeatCount = .infinity | |
| gradientLayer.add(animation, forKey: "") | |
| let color = JPNewThemeManager.shared()?.createColor("secondaryButtonColor") | |
| subviews.forEach({ $0.cornerRadius = 5; $0.backgroundColor = color }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment