Latest 1.0.0
Homepage https://github.com/anelad/ANActivityIndicator
License MIT
Platforms ios 10.0
Authors

Xcode 9.0+
iOS 10.0+
Swift 4.0+
Version
carthage

ANActivityIndicator is pre-built indicator animations library, based on DGActivityIndicatorView by gotnovik and GTMActivityIndicatorView by GTMYang inspired from loaders.css by CONNOR ATHERTON.

Why did I create ANActivityIndicator in a seperate repo?

First of all, I don’t mean to get all the credits on this project. I did not do anything worthy comparing gotnovik’s & GTMYang’s works.

So why did I created ANActivityIndicator in a seperate repo?

It looks like gotnovik is not updating his repo and GTMYang’s repo focuses on a bit different usage approach comparing mine.

General Differences

between DGActivityIndicatorView

  • Implemented with Swift

between GTMActivityIndicatorView

  • Implemented with Swift 4
  • Ready to use pre-built indicator animations. With GTMActivityIndicatorView, you have to add animations into your project manually.

Added Features

  • Custom animations structure (a struct like NSNotification.Name).
  • Custom loading message margin.

Demo

Check Pre-Built Animation Types section to see animations’ type.

demo-gif

Requirements

  • XCode 9.x or higher
  • Swift 4.x
  • iOS 10.0 or higher

Installation

CocoaPods

pod 'ANActivityIndicator'

Manually

  1. Download the repo.

As Framework

  1. Copy ANActivityIndicator and Source folders into your workspace directory.
  2. Add [workspace directory]/ANActivityIndicator/ANActivityIndicator.xcodeproj into your "workspace".
  3. In Project settings -> General add ANActivityIndicator.framework to Embedded Binaries & Linked Framework and Libraries

As SubProject

  1. Copy ANActivityIndicator and Source folders into your project directory.
  2. Add ANActivityIndicator/ANActivityIndicator.xcodeproj into your "project".

As Code

  1. Copy ANActivityIndicator and Source folders into your workspace / project directory.
  2. Add contents of [workspace / project directory]/Source folder into your workspace / project.

Usage

Import

If you installed as framework or subproject; first

import ANActivityIndicator

Initialization

As view

let indicator = ANActivityIndicatorView.init(
        frame: CGrect,
        animationType: ANAnimationIndicatorType,
        color: UIColor,
        padding: CGFloat)

aView.addSubview(indicator)

For initialization as fullscreen; refer to Show / Hide Indicator -> As Full-Screen section.

Show / Hide Indicator

You have to ways to show ANActivityIndicator

As view

let indicator = ANActivityIndicatorView.init(...)

indicator.startAnimating()

indicator.stopAnimating()

As Full-Screen

You can show full-screen indicator in every class.

In UIViewController or its subclasses

//default
showIndicator()

hideIndicator()
//custom
showIndicator(
        CGSize,
        message: String,
        messageFont: UIFont,
        messageTopMargin: CGFloat,
        animationType: ANActivityIndicatorAnimationType,
        color: UIColor,
        padding: CGFloat,
        displayTimeThreshold: TimeIntervalInNanoseconds,
        minimumDisplayTime: TimeIntervalInNanoseconds)

hideIndicator()

In every class

//default
ANActivityIndicatorPresenter.shared.showIndicator()

ANActivityIndicatorPresenter.shared.hideIndicator()
//custom
ANActivityIndicatorPresenter.shared.showIndicator(
        CGSize,
        message: String,
        messageFont: UIFont,
        messageTopMargin: CGFloat,
        animationType: ANActivityIndicatorAnimationType,
        color: UIColor,
        padding: CGFloat,
        displayTimeThreshold: TimeIntervalInNanoseconds,
        minimumDisplayTime: TimeIntervalInNanoseconds)

ANActivityIndicatorPresenter.shared.hideIndicator()

Pre-Built Animation Types

Here are the list of pre-built animations. You can see their look in Demo section. (Ordered with numbers)

  1. .audioEqualizer
  2. .ballBeat
  3. .ballClipRotate
  4. .ballClipRotateMultiple
  5. .ballClipRotatePulse
  6. .ballGridBeat
  7. .ballGridPulse
  8. .ballPulse
  9. .ballPulseRise
  10. .ballPulseSync
  11. .ballRotate
  12. .ballRotateChase
  13. .ballScale
  14. .ballScaleMultiple
  15. .ballScaleRipple
  16. .ballScaleRippleMultiple
  17. .ballSpinFadeLoader
  18. .ballTrianglePath
  19. .ballZigZag
  20. .ballZigZagDeflect
  21. .blank
  22. .cubeTransition
  23. .lineScale
  24. .lineScaleParty
  25. .lineScalePulseOut
  26. .lineScalePulseOutRapid
  27. .lineSpinFadeLoader
  28. .orbit
  29. .pacman
  30. .semiCircleSpin
  31. .squareSpin
  32. .triangleSkewSpin

Custom Animations

ANActivityIndicator has a custom animation structure like NSNotification.Name.

  • First create a class inherits from ANActivityIndicatorAnimation protocol:

    class CustomIndicatorAnimation : ANActivityIndicatorAnimation{
        required init() { }
    
        func setUpAnimation(in layer: CALayer, size: CGSize, color: UIColor) {
                ......
                //implement your animation
                //to learn how to implement, check example project or source codes.
                .....
        }
    }
  • Then add ANActivityIndicatorAnimationType for your custom animation:
extension ANActivityIndicatorAnimationType{
        public static let customIndicatorAnimation = ANActivityIndicatorAnimationType.init(animation: CustomIndicatorAnimation.self)
}
  • Now you can call your custom animation via its type:
    ANActivityIndicatorAnimationType.customIndicatorAnimation

Defaults

  • Animation type:
    ANActivityIndicatorAnimationType.ballSpinFadeLoader
  • Color of indicator:
    UIColor.white
  • Padding of indicator:
    CGFloat = 0
  • Message:
    String = ""
  • Message font:
    UIFont.boldSystemFont(ofSize: 20)
  • Message margin to indicator:

    CGFloat = 8
  • Display time threshold:

    Default time that has to be elapsed (between calls of startAnimating() and stopAnimating()) in order to actually display UI blocker. It should be set thinking about what the minimum duration of an activity is to be worth showing it to the user. If the activity ends before this time threshold, then it will not be displayed at all.

    CGFloat = 0
  • Minimum display time:

    Default minimum display time of UI blocker. Its main purpose is to avoid flashes showing and hiding it so fast. For instance, setting it to 200ms will force UI blocker to be shown for at least this time (regardless of calling stopAnimating() ealier).

    CGFloat = 0
  • Fullscreen indiator default size:
    CGSize.init(width: 60, height: 60)

    License

    This project is under MIT License. Check LICENSE file.

Contribute

I’m very welcome any contributions. Please read the CONTRIBUTING file.

  • Be sure you fulfill the pull request template.
  • Be sure your code passes TravisCI. (Not implemented yet.)

Issues

Please fulfill issue template before posting.

Authors

ANActivityIndicator implemented by

Arda Oğul Üçpınar.

Latest podspec

{
    "name": "ANActivityIndicator",
    "version": "1.0.0",
    "summary": "ANActivityIndicator is pre-built indicator animations library written in Swift4.",
    "description": "ANActivityIndicator is pre-built indicator animations library written in Swift4. You can easily create and show indicators locally or globally. Also you can create custom animations.",
    "homepage": "https://github.com/anelad/ANActivityIndicator",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Arda Ou011ful u00dcu00e7pu0131nar": "[email protected]"
    },
    "source": {
        "git": "https://github.com/anelad/ANActivityIndicator.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/ArdaUcpinar",
    "platforms": {
        "ios": "10.0"
    },
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "Source/Classes/**/*"
}

Pin It on Pinterest

Share This