SkeletonView

repository·main·Indexed 12 days ago

https://github.com/juanpe/skeletonview

An iOS framework for providing skeleton loading views to indicate asynchronous processes. It allows any UIView to be skeletonable via the isSkeletonable property and supports recursive skeletonization, custom text appearance, and integration with UITableView and UICollectionView through SkeletonTableViewDataSource and SkeletonCollectionViewDataSource protocols. Supports CocoaPods, Carthage, Swift Package Manager, and XCFrameworks (since version 1.30.0).

Tokens
9.6K
Snippets
42
Records
47
Agent score
90%

What's inside SkeletonView

  1. Overview of SkeletonView features

    main

    SkeletonView is an elegant way to show users that something is processing (like API requests) by using skeleton views instead of standard spinners. This prepares users visually for the content they are expecting.

    Key features include:

    • Easy to use
    • All UIViews are skeletonable
    • Highly customizable
    • Universal support (iPhone & iPad)
    • Interface Builder friendly
  2. Understand the SkeletonView recursion hierarchy

    main

    SkeletonView is recursive: when you trigger a skeleton effect on a container, it searches for subviews to animate. To ensure efficiency and control where the recursion stops, you must explicitly set isSkeletonable = true on the views you want to participate in the skeleton effect.

    If a container view is not marked as isSkeletonable, the recursion stops at that view, and its subviews will not be animated even if they are marked as skeletonable. To animate an entire hierarchy, you must mark the parent containers as isSkeletonable.

  3. Understand the skeletonable hierarchy requirement

    main

    SkeletonView works recursively to find views to apply the skeleton effect to. To ensure efficiency, the recursion stops as soon as it encounters a view that is not marked as skeletonable.

    For the skeleton to appear on subviews, the parent container must have its isSkeletonable property set to true. If a container is not skeletonable, SkeletonView will not search its subviews, even if they are marked as skeletonable.

    // Example of showing a skeleton on a view hierarchy
    view.showSkeleton()
  4. Quickstart: Use SkeletonView in 3 steps

    main

    To use SkeletonView, follow these three steps:

    1. Import the framework:

      import SkeletonView
    2. Enable skeletonization: Mark the views you want to be skeletonable. You can do this via code or in Interface Builder/Storyboards.

      • Code: view.isSkeletonable = true
      • IB/Storyboard: Check the isSkeletonable box in the inspector.
    3. Show the skeleton: Call one of the following methods on the view to display the skeleton effect:

      • view.showSkeleton(): Solid color.
      • view.showGradientSkeleton(): Gradient color.
      • view.showAnimatedSkeleton(): Animated solid color.
      • view.showAnimatedGradientSkeleton(): Animated gradient color.

    Note on Recursion: SkeletonView is recursive. If you want to show skeletons in all skeletonable subviews, you only need to call the show method on the main container view (e.g., a UIViewController's root view).

    import SkeletonView
    
    // 1. Enable skeletonization
    avatarImageView.isSkeletonable = true
    
    // 2. Show the skeleton
    view.showAnimatedGradientSkeleton()
  5. Quickstart: How to use SkeletonView

    main

    To use SkeletonView, follow these three steps:

    1. Import the framework: import SkeletonView.
    2. Enable skeletonization: Set isSkeletonable = true on the views you want to animate. You can do this in code or via Interface Builder/Storyboards.
    3. Show the skeleton: Call one of the following methods on your view:
      • showSkeleton(): Solid color.
      • showGradientSkeleton(): Gradient color.
      • showAnimatedSkeleton(): Solid color with animation.
      • showAnimatedGradientSkeleton(): Gradient color with animation.

    Note on Recursion: SkeletonView is recursive. If you want to show skeletons in all subviews, you only need to call the show method on the main container view (e.g., a UIViewController's root view), provided the subviews are marked as isSkeletonable.

    import SkeletonView
    
    // 1. Set the view as skeletonable
    avatarImageView.isSkeletonable = true
    
    // 2. Show the skeleton
    view.showAnimatedGradientSkeleton()
  6. Install SkeletonView via CocoaPods or Carthage

    main

    You can integrate SkeletonView into your project using either CocoaPods or Carthage.

    CocoaPods Add the following to your Podfile:

    pod "SkeletonView"

    Carthage Add the following to your Cartfile:

    gitub "Juanpe/SkeletonView"
    pod "SkeletonView"
    # or
    gitub "Juanpe/SkeletonView"
  7. How to use SkeletonView

    main

    To use SkeletonView, follow these three steps:

    1. Import the framework:

      import SkeletonView
    2. Enable skeleton support: Set the isSkeletonable property to true on the views you want to animate. You can do this in code or via Interface Builder/Storyboard.

      avatarImageView.isSkeletonable = true
    3. Show the skeleton: Call one of the following methods on your view to display different skeleton styles:

      • view.showSkeleton(): Solid color.
      • view.showGradientSkeleton(): Gradient color.
      • view.showAnimatedSkeleton(): Solid color with animation.
      • view.showAnimatedGradientSkeleton(): Gradient color with animation.

    Important: SkeletonView is recursive. To show skeletons for all subviews, call the show method on the main container view (e.g., a UIViewController's view).

    import SkeletonView
    
    // 1. Enable
    avatarImageView.isSkeletonable = true
    
    // 2. Show
    view.showAnimatedGradientSkeleton()
  8. Use XCFrameworks for SkeletonView

    main

    Since version 1.30.0, SkeletonView supports XCFrameworks. If you specifically require an XCFramework installation, use the dedicated repository instead of the main one.

    https://github.com/Juanpe/SkeletonView-XCFramework.git
  9. How to use SkeletonView in 3 steps

    main

    To implement skeleton views in your application, follow these three steps:

    1. Import the framework:

      import SkeletonView
    2. Enable skeletonization: Set isSkeletonable = true on the views you want to animate. You can do this in code or via Interface Builder/Storyboards.

      avatarImageView.isSkeletonable = true
    3. Show the skeleton: Call one of the four available skeleton effects on your view:

      • view.showSkeleton(): Solid color.
      • view.showGradientSkeleton(): Gradient effect.
      • view.showAnimatedSkeleton(): Solid color animation.
      • view.showAnimatedGradientSkeleton(): Gradient animation.

    Note: SkeletonView is recursive. If you call a show method on a container view (like a UIViewController's view), it will automatically apply the effect to all its isSkeletonable subviews.

    import SkeletonView
    
    avatarImageView.isSkeletonable = true
    view.showAnimatedGradientSkeleton()
  10. How to use SkeletonView in your app

    main

    Using SkeletonView involves three main steps:

    1. Import the framework: import SkeletonView.
    2. Mark views as skeletonable: Set the isSkeletonable property to true for any UIView you want to show a skeleton for. You can do this in code or via Interface Builder/Storyboards.
    3. Show the skeleton: Call one of the following methods on the view:
      • view.showSkeleton(): Solid color.
      • view.showGradientSkeleton(): Gradient color.
      • view.showAnimatedSkeleton(): Solid color with animation.
      • view.showAnimatedGradientSkeleton(): Gradient color with animation.

    Note: SkeletonView is recursive. If you set isSkeletonable = true on a container view, calling a show... method on that container will automatically apply skeletons to all its skeletonable subviews.

    import SkeletonView
    
    // 1. Mark as skeletonable
    avatarImageView.isSkeletonable = true
    
    // 2. Show skeleton
    view.showAnimatedGradientSkeleton()