Skip to content

An easy way to add a simple, shimmering effect to any view in an iOS app using Swift

License

Notifications You must be signed in to change notification settings

eugeneego/Shimmer

 
 

Repository files navigation

Shimmer

Shimmer is an easy way to add a shimmering effect to any view in your app. It's useful as an unobtrusive loading indicator.

Shimmer was originally developed to show loading status in Paper (no longer online).

Shimmer

Usage

To use Shimmer, create a ShimmeringView or ShimmeringLayer and add your content. To start shimmering, set the shimmering property to true.

An example of making a label shimmer:

let shimmeringView = ShimmeringView(frame: view.bounds)
view(addSubview: shimmeringView)

let loadingLabel = UILabel(frame: shimmeringView.bounds)
loadingLabel.textAlignment = .center
loadingLabel.text = "Shimmer"
shimmeringView.contentView = loadingLabel

// Start shimmering.
shimmeringView.isShimmering = true

There's also an example project. In the example, you can swipe horizontally and vertically to try various shimmering parameters, or tap to start or stop shimmering. (To build the example locally, you'll need to open Shimmering.xcworkpace rather than the .xcodeproj.)

Installation

There are following options:

  1. Swift Package Manager. Add https://github.com/eugeneego/Shimmer.git to your Package Dependencies in Xcode. Or add .package(url: "https://github.com/eugeneego/Shimmer.git", from: "1.0.0") to dependencies block in Package.swift file.
  2. Carthage. Add github "eugeneego/Shimmer" to your Cartfile.
  3. Cocoapods. Add pod 'Shimmer', :git => 'https://github.com/eugeneego/Shimmer.git' to your Podfile.
  4. Manually. Just add Shimmering/ShimmeringView.swift into your Xcode project. Slightly simpler, but updates are also manual.

Shimmer requires iOS 11 or later.

How it works

Shimmer uses the CALayer.mask property to enable shimmering, similar to what's described in John Harper's 2009 WWDC talk (unfortunately no longer online). Shimmer uses CoreAnimation's timing features to smoothly transition "on-beat" when starting and stopping the shimmer.

Other Platforms

We have a version of Shimmer for Android, too! It's also available on GitHub.

Contributing

See the CONTRIBUTING file for how to help out.

License

Shimmer is BSD-licensed.

About

An easy way to add a simple, shimmering effect to any view in an iOS app using Swift

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 94.4%
  • Ruby 3.0%
  • Objective-C 2.6%