ShimmerSwift

repository·master·Indexed 41 days ago

https://github.com/beaunouvelle/shimmerswift

A Swift implementation of the Facebook shimmer effect for iOS 9.0+ and Swift 5.1+. It provides ShimmeringView and ShimmeringLayer to animate content with a customizable light-sweep effect, including controls for speed, direction, highlight length, and opacity.

Tokens
729
Snippets
2
Records
3
Agent score
2%

What's inside ShimmerSwift

  1. Install ShimmerSwift

    master

    You can install ShimmerSwift using several dependency managers or via manual installation:

    • Manual: Download the .zip from the repository and drag the Shimmer folder into your Xcode project.
    • Carthage: Add github "BeauNouvelle/ShimmerSwift" to your Cartfile.
    • CocoaPods: Add pod 'ShimmerSwift' to your Podfile.
    • Swift Package Manager (SPM): In Xcode 11+, go to File > Swift Packages > Add Package Dependency and use the repository URL.
    # Carthage
    github "BeauNouvelle/ShimmerSwift"
    
    # CocoaPods
    pod 'ShimmerSwift'
  2. Use ShimmeringView to add shimmer effects

    master

    To apply a shimmer effect to a view, create a ShimmeringView (or ShimmeringLayer), assign your target view to its contentView property, and set isShimmering to true.

    Requirements:

    • Swift 5.1+
    • iOS 9.0+
    // Setup ShimmeringView
    let shimmerView = ShimmeringView(frame: self.view.bounds)
    self.view.addSubview(shimmerView)
    
    // Setup the view you want shimmered
    let label = UILabel(frame: shimmerView.bounds)
    label.text = "This is my shimmering text"
    
    // Add the view you want shimmered to the `shimmerView`
    shimmerView.contentView = label
    
    // Start shimmering
    shimmerView.isShimmering = true
    
    // To stop shimmering
    shimmerView.isShimmering = false
  3. Configure ShimmeringView properties

    master

    You can customize the behavior and appearance of the shimmer effect using the following properties on ShimmeringView:

    PropertyTypeDefaultDescription
    contentViewUIViewN/AThe content view to be shimmered.
    isShimmeringBoolfalseSet to true to start animation, false to stop.
    shimmerSpeedCGFloat230Speed in points per second. Higher is faster.
    shimmerHighlightLengthCGFloat1.0Highlight length. Range: [0, 1].
    shimmerDirectionShimmer.Direction.rightDirection of animation (e.g., .right runs left to right).
    shimmerPauseDurationCFTimeInterval0.4Time interval between shimmers in seconds.
    shimmerAnimationOpacityCGFloat0.5Opacity of the content during a shimmer.
    shimmerOpacityCGFloat1.0Opacity of the content when not shimmering.
    shimmerBeginFadeDurationCFTimeInterval0.1Duration of the fade when shimmer begins.
    shimmerEndFadeDurationCFTimeInterval0.3Duration of the fade when shimmer ends.