Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Created February 27, 2020 00:27
Show Gist options
  • Select an option

  • Save dnedrow/20f1a5e40fa51c3cabf4d7b6819486fa to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/20f1a5e40fa51c3cabf4d7b6819486fa to your computer and use it in GitHub Desktop.
Provides a shimmer animation for labels.
//
// 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