I have a large text and want to add an effect that is similar to the slide to unlock one of the latest iOS and that will go from top to bottom with the text sliding from bottom to top.
Update with swift shimmering label, view etc...
import UIKit
import QuartzCore
class ViewController: UIViewController {
@IBOutlet var testLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.testLabel.startShimmering()
}
}
extension UIView {
func startShimmering() {
// let light = UIColor.init(white: 0, alpha: 0.1).cgColor
let light = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
let dark = UIColor.black.cgColor
let gradient: CAGradientLayer = CAGradientLayer()
gradient.colors = [dark, light, dark]
gradient.frame = CGRect(x: -self.bounds.size.width, y: 0, width: 3*self.bounds.size.width, height: self.bounds.size.height)
gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
gradient.endPoint = CGPoint(x: 1.0, y: 0.525)
gradient.locations = [0.4, 0.5, 0.6]
self.layer.mask = gradient
let animation: CABasicAnimation = CABasicAnimation(keyPath: "locations")
animation.fromValue = [0.0, 0.1, 0.2]
animation.toValue = [0.8, 0.9, 1.0]
animation.duration = 1.5
animation.repeatCount = HUGE
gradient.add(animation, forKey: "shimmer")
}
func stopShimmering() {
self.layer.mask = nil
}
}
I suggest you use Grant Pauls's Shimmer control, because it does just that.
https://github.com/facebook/Shimmer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With