Code Monkey home page Code Monkey logo

ccactivityhud's Introduction

CCActivityHUD

From v2.0.0, I rename it from CCActivityIndicatorView to CCActivityHUD. if you have forked the project bofore I rename it, you should run the command below to make a Pull Request correctly.

git remote set-url origin [email protected]:Cokile/CCActivityHUD.git

Captures

Installation

Use Cocoapods

Simply add one line to your Podfile:

pod 'CCActivityHUD'

Note: If you have used pod 'CCActivityIndicatorView' in your Podfile, just replace it with pod 'CCActivityHUD' to update the pod.

Manually

Add all the files in the CCActivityHUD folder to your project.

Add ImageIO.framework to your target.

Easy to use

#import "CCActivityIndicatorView.h"

self.activityHUD = [CCActivityIndicatorView new];

// Show with the default type.
[self.myactivityHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
	// Your task code here
	dispatch_async(dispatch_get_main_queue(), ^{
    	// When the task has completed.
        [self.activityHUD dismiss];
        });
    });

More options

  • Instead of using show to show the default indicator animation type, you can specify the type to show (To see what tpyes you can use, see Indicator animation type section).
[self.activityHUD showWithType:CCActivityHUDIndicatorTypeDynamicArc];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
	// Your task code here
	dispatch_async(dispatch_get_main_queue(), ^{
    	// When the task has completed.
        [self.activityHUD dismiss];
        });
    });

Note: You should not use showWithType: within viewDidLoad, The Animation will not work! Instead, show it within viewWillAppear or viewDidAppear.

  • Do not like the provided indicator animation? CCActivityHUD supports GIF too. Just grab a GIF you like and show with it.
[self.activityHUD showWithGIFName:@"test.gif"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
	// Your task code here
	dispatch_async(dispatch_get_main_queue(), ^{
    	// When the task has completed.
        [self.activityHUD dismiss];
        });
    });
  • Or just want to show some text to users? CCActivityHUD also supports showing text, even with shimmering visual effect.
[self.activityHUD showWithText:@"Now loading..." shimmering:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
	// Your task code here
	dispatch_async(dispatch_get_main_queue(), ^{
    	// When the task has completed.
        [self.activityHUD dismiss];
        });
    });
  • CCActivityHUD also support progress. Use showWithProgress and perform your task code. In the call back method, update UI in the main thread by self.activityHUD.progress = completedTaskAmount/totalTaskAmount, When all the tasks have completed, use[self.activityHUD dismiss].

  • Last but not least, you sometimes need to show some text to users as a feedback when a task has completed rather than simply dismiss a HUD. CCActivityHUD also support it.

// Set success to NO will show a cross, and vice versa, YES means showing a tick.
// If you set the text to nil, self.activityHUD will only show a tick or cross according to the success parameter.
[self.activityHUD dismissWithText:@"This is a sample dismiss text" delay:0.7 success:NO]

Customisable

Public properties

// Set public properties before showing it.

// Set the backgrond color. The default color is black.
self.activityHUD.backColor = <#UIColor#>;

// Set the background border color. The default background color is black.
self.activityHUD.borderColor = <#UIColor#>;

// Set the backgrond border width. THe default value is 0.
self.activityHUD.borderWidth = <#CGFloat#>;

// Set the background corner radius. The default value is 5.0;
self.activityHUD.cornerRadius = <#CGFloat#>;

// Set the indicator color. The default color is white.
self.activityHUD.indicatorColor = <#UIColor#>;

// Set the boolean value that indicates whether ohter UIViews are user-interactable. The default value is YES.
self.activityHUD.isTheOnlyActiveView = <#BOOL#>;

// Set the appear animation type.
self.activityHUD.appearAnimationType = <#CCActivityHUDAppearAnimationType#>;

//  Set the disappear animation type.
self.activityHUD.disappearAnimationType = <#CCActivityHUDAppearAnimationType#>;

// Set the overlay type
self.activityHUD.overlayType = <#CCActivityHUDOverlayType#>;

Animation Type

Indicator animation type

typedef NS_ENUM(NSInteger, CCActivityHUDIndicatorType) {
    CCActivityHUDIndicatorTypeScalingDots, // Default type
    CCActivityHUDIndicatorTypeLeadingDots,
    CCActivityHUDIndicatorTypeMinorArc,
    CCActivityHUDIndicatorTypeDynamicArc,
    CCActivityHUDIndicatorTypeArcInCircle,
    CCActivityHUDIndicatorTypeSpringBall
};

Appear animation type

typedef NS_ENUM(NSInteger, CCActivityHUDAppearAnimationType) {
    CCActivityHUDAppearAnimationTypeSlideFromTop,
    CCActivityHUDAppearAnimationTypeSlideFromBottom,
    CCActivityHUDAppearAnimationTypeSlideFromLeft,
    CCActivityHUDAppearAnimationTypeSlideFromRight,
    CCActivityHUDAppearAnimationTypeZoomIn,
    CCActivityHUDAppearAnimationTypeFadeIn // Default type
};

Disappear animation type

typedef NS_ENUM(NSInteger, CCActivityHUDDisappearAnimationType) {
    CCActivityHUDDisappearAnimationTypeSlideToTop,
    CCActivityHUDDisappearAnimationTypeSlideToBottom,
    CCActivityHUDDisappearAnimationTypeSlideToLeft,
    CCActivityHUDDisappearAnimationTypeSlideToRight,
    CCActivityHUDDisappearAnimationTypeZoomOut,
    CCActivityHUDDisappearAnimationTypeFadeOut // Default type
};

Overlay type

typedef NS_ENUM(NSInteger, CCActivityHUDOverlayType) {
    CCActivityHUDOverlayTypeNone, // Default type
    CCActivityHUDOverlayTypeBlur,
    CCActivityHUDOverlayTypeTransparent,
    CCActivityHUDOverlayTypeShadow
};

Requirement

iOS 8.0 or later

Acknowledgement

uiimage-from-animated-gif : A UIImage category that loads animated GIFs. It provides me with the awesome API to integrate GIF into CCActivityHUD with few efforts.

TODO

  • More types of animation

Any Pull Requests are welcome.

ccactivityhud's People

Contributors

cokile avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.