ANActivityIndicator is pre-built indicator animations library, based on DGActivityIndicatorView by gotnovik and GTMActivityIndicatorView by GTMYang inspired from loaders.css by CONNOR ATHERTON.
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.
- Implemented with Swift
- Implemented with Swift 5
- Ready to use pre-built indicator animations. With GTMActivityIndicatorView, you have to add animations into your project manually.
- Custom animations structure (a struct like NSNotification.Name).
- Custom loading message margin.
Check Pre-Built Animation Types section to see animations' type.
- Swift 5
- iOS 12.0 or higher
pod 'ANActivityIndicator'
- Download the repo.
- Copy
ANActivityIndicator
andSource
folders into your workspace directory. - Add
[workspace directory]/ANActivityIndicator/ANActivityIndicator.xcodeproj
into your "workspace". - In
Project settings -> General
addANActivityIndicator.framework
toEmbedded Binaries
&Linked Framework and Libraries
- Copy
ANActivityIndicator
andSource
folders into your project directory. - Add
ANActivityIndicator/ANActivityIndicator.xcodeproj
into your "project".
- Copy
ANActivityIndicator
andSource
folders into your workspace / project directory. - Add contents of
[workspace / project directory]/Source
folder into your workspace / project.
If you installed as framework or subproject; first
import ANActivityIndicator
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.
You have to ways to show ANActivityIndicator
let indicator = ANActivityIndicatorView.init(...)
indicator.startAnimating()
indicator.stopAnimating()
You can show full-screen indicator in every class.
//default
showIndicator()
hideIndicator()
//custom
showIndicator(
CGSize,
message: String,
messageFont: UIFont,
messageTopMargin: CGFloat,
animationType: ANActivityIndicatorAnimationType,
color: UIColor,
padding: CGFloat,
displayTimeThreshold: TimeIntervalInNanoseconds,
minimumDisplayTime: TimeIntervalInNanoseconds)
hideIndicator()
//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()
Here are the list of pre-built animations. You can see their look in Demo section. (Ordered with numbers)
- .audioEqualizer
- .ballBeat
- .ballClipRotate
- .ballClipRotateMultiple
- .ballClipRotatePulse
- .ballGridBeat
- .ballGridPulse
- .ballPulse
- .ballPulseRise
- .ballPulseSync
- .ballRotate
- .ballRotateChase
- .ballScale
- .ballScaleMultiple
- .ballScaleRipple
- .ballScaleRippleMultiple
- .ballSpinFadeLoader
- .ballTrianglePath
- .ballZigZag
- .ballZigZagDeflect
- .blank
- .cubeTransition
- .lineScale
- .lineScaleParty
- .lineScalePulseOut
- .lineScalePulseOutRapid
- .lineSpinFadeLoader
- .orbit
- .pacman
- .semiCircleSpin
- .squareSpin
- .triangleSkewSpin
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
- 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)
This project is under MIT License. Check LICENSE file.
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.)
Please fulfill issue template
before posting.
- Base project created by gotnovik.
- Swift version implemented by GTMYang.
- Project inspired from CONNOR ATHERTON's project.
Arda Oğul Üçpınar.