ndduong ndduong - 4 months ago 16
Swift Question

How do you add Facebook shimmering to images and UIViews?

I'm trying out Facebook shimmering library and I was able to add shimmering to text label using this code.

self.shimmeringView = FBShimmeringView(frame: CGRectMake(0, 0, 200, (self.navigationController?.navigationBar.bounds.height)!))
self.shimmeringView.contentView = navLabel
self.navigationItem.titleView = self.shimmeringView
self.shimmeringView.shimmering = true

However, I am unable to make an image or an UIImage shimmer. Is this even possible? Thanks!


What you are doing for shimmering the UIImageView is wrong.

  1. You never add shimmer to the view as a subview.
  2. You don't set the UIImageView as the contentView for the shimmer

Update your code with

@IBOutlet var imageView: UIImageView!

var shimmer: FBShimmeringView!

override func viewDidLoad() {
    shimmer = FBShimmeringView(frame: self.imageView.frame)
    shimmer.contentView = imageView
    shimmer.shimmering = true