Coder Social home page Coder Social logo

irons163 / iralertmanager Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 581 KB

IRAlertManager is a powerful alert manager for iOS, which can handle different alert frameworks.

License: MIT License

Objective-C 98.59% Ruby 1.41%
alertmanager alert-manager ios objcective-c alert

iralertmanager's Introduction

Build Status Platform

IRAlertManager

  • IRAlertManager is a powerful alert manager for iOS, which can handle different alert frameworks.

Features

  • Handle different alert frameworks.
  • Support a global loading view.

Install

Git

  • Git clone this project.
  • Copy this project into your own project.
  • Add the .xcodeproj into you project and link it as embed framework.

Options

  • You can remove the demo and ScreenShots folder.

Cocoapods

  • Add pod 'IRAlertManager' in the Podfile
  • pod install

Usage

Basic

  • The demo show three diffrent alert systems, include Apple system alert, XFDialogBuilder, and LGAlertView.

  • Assum you want to handle with a alert system named DEMOAlert, you can follow as below:

  • Create a new class IRDEMOAlert extends IRAlert, and Import IRAlertManager

#import <IRAlertManager/IRAlertManager.h>

typedef NS_ENUM(NSUInteger, IRDEMOAlertStyle) {
    IRDEMOAlertStyleAlert       = 0,
    IRDEMOAlertStyleActionSheet = 1
};

@interface IRDEMOAlert : IRAlert

- (instancetype)initWithTitle:(nullable NSString *)title
               message:(nullable NSString *)message
                 style:(IRDEMOAlertStyle)style
         buttonActions:(nullable NSArray<IRAlertAction *> *)buttonActions
    cancelButtonAction:(nullable IRAlertAction *)cancelButtonAction
destructiveButtonAction:(nullable IRAlertAction *)destructiveButtonAction;

@end
  • Write the initial codes for create the DEMOAlert instanse inside
- (instancetype)initWithTitle:(nullable NSString *)title
               message:(nullable NSString *)message
                 style:(IRAlertLGStyle)style
         buttonActions:(nullable NSArray<IRAlertAction *> *)buttonActions
    cancelButtonAction:(nullable IRAlertAction *)cancelButtonAction
destructiveButtonAction:(nullable IRAlertAction *)destructiveButtonAction {
    if(self = [super init]){
        NSMutableArray<NSString *> * titles = [self titlesWithButtonActions:buttonActions];
        
        alert = [[DEMOAlert alloc] initWithTitle:title message:message style:(DEMOAlertStyle)style buttonTitles:titles cancelButtonTitle:cancelButtonAction.title destructiveButtonTitle:destructiveButtonAction.title];
        
        [self setupButtonActions:buttonActions cancelButtonAction:cancelButtonAction destructiveButtonAction:destructiveButtonAction];
        [self registerForKeyboardNotifications];
    }
    
    return self;
}
  • Override IRAlert methods
-(void)setBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor;
-(void)setCornerRadius:(CGFloat)cornerRadius;
-(void)addAction:(IRAlertAction*)action;
  • Let the IRAlertAction work for DEMOAlert, this is the most difficualt part, you need know how to use DEMOAlert, and make DEMOAlert call the handler of IRAlertAction. In this example, DEMOAlert has actionHandler, cancelHandler, and destructiveHandler, and each handler is mapping to IRAlertAction
- (void)setupButtonActions:(NSArray<IRAlertAction *> * _Nullable)buttonActions cancelButtonAction:(IRAlertAction * _Nullable)cancelButtonAction destructiveButtonAction:(IRAlertAction * _Nullable)destructiveButtonAction {
    __weak IRDEMOAlert* wself = self;
    
    alert.actionHandler = ^(DEMOAlert * _Nonnull alertView, NSUInteger index, NSString * _Nullable title) {
        if(index >= buttonActions.count)
            return;
        
        IRAlertAction *action = [buttonActions objectAtIndex:index];
        action.handler(action);
    };
    
    alert.cancelHandler = ^(DEMOAlert * _Nonnull alertView) {
        if (cancelButtonAction) {
            cancelButtonAction.handler(cancelButtonAction);
        }
    };
    
    alert.destructiveHandler = ^(DEMOAlert * _Nonnull alertView) {
        if (destructiveButtonAction) {
            destructiveButtonAction.handler(destructiveButtonAction);
        }
    };
}
  • Show or Hide alert with IRAlertManager.
[[IRAlertManager sharedInstance] showAlert:alert];

[[IRAlertManager sharedInstance] hideAlert:alert];
  • Show or Hide global loading view with IRAlertManager.
[[IRAlertManager sharedInstance] showLoadingViewWithTarget:self backgroundImage:[ViewController imageWithColor:[UIColor greenColor] Size:[UIScreen mainScreen].bounds.size]];

[[IRAlertManager sharedInstance] hideLoadingViewWithTarget:self];
  • Show DEMOAlert with loading view
- (IBAction)showDEMOAlert:(id)sender {
    IRAlertAction *commitAction = [[IRAlertAction alloc] init];
    commitAction.title = @"OK";
    commitAction.style = IRAlertActionStyleDefault;

    IRAlertAction *cancelAction = [[IRAlertAction alloc] init];
    cancelAction.title = @"Cancel";
    cancelAction.style = IRAlertActionStyleCancel;
    
    alert = [[IRDEMOAlert alloc] initWithTitle:nil message:nil style:IRDEMOAlertStyleAlert buttonActions:@[commitAction] cancelButtonAction:cancelAction destructiveButtonAction:nil];
    
    __weak IRAlert *wAlert = alert;
    commitAction.handler = ^(IRAlertAction * _Nonnull action) {
        [[IRAlertManager sharedInstance] hideAlert:wAlert];
    };
    __weak ViewController *wSelf = self;
    cancelAction.handler = ^(IRAlertAction * _Nonnull action) {
        [[IRAlertManager sharedInstance] hideLoadingViewWithTarget:wSelf];
    };
    
    [alert setCornerRadius:20];
    [[IRAlertManager sharedInstance] showAlert:alert];
}

Screenshots

Show Alert for XFDialogBuilder Show Custom View for XFDialogBuilder
Show Alert for XFDialogBuilder Show Custom View for XFDialogBuilder
Show Alert for LGAlert Show Custom View for LGAlert
Show Alert for LGAlert Show Custom View for LGAlert
Show System Action Sheet Show System Alert
Show System Action Sheet Show System Alert
Main Page Show System Alert And Loding Page
Main Page Show System Alert And Loding Page

iralertmanager's People

Stargazers

 avatar

Watchers

 avatar  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.