#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface Zmstatubarhud:nsobject
Show message when successful
+ (void) showsuccess: (NSString *) msg;
Show a message when it fails
+ (void) ShowError: (NSString *) msg;
Load the show call this method to hide the need to call the Hide method yourself
+ (void) showloading: (NSString *) msg;
Hide Cue Box
+ (void) hide;
Display information
+ (void) ShowMessage: (NSString *) msg;
Custom Prompt box
+ (void) ShowMessage: (NSString *) msg Image: (UIImage *) image;
@end
//
Zmstatubarhud.m
Status bar HUD232
//
Created by Zhang Ming on 16/3/7.
copyright©2016 Ming. All rights reserved.
//
#define Mmfont [Uifont systemfontofsize:13]
#import "ZMStatuBarHud.h"
Static UIWindow *window_;
Static Nstimer *timer_;
Message animation hidden Time
static CGFloat Const Mmmessageduration = 0.25;
@implementation Zmstatubarhud
/* Create window */
+ (void) Setupwindow
{
CGFloat windowh = 20;
CGRect frame = CGRectMake (0,-WINDOWH, [UIScreen mainscreen].bounds.size.width, WINDOWH);
Window_.hidden = YES;
Window_ = [[UIWindow alloc]init];
Window_.frame = frame;
Window_.hidden = NO;
Window_.windowlevel = Uiwindowlevelalert;
Window_.backgroundcolor = [Uicolor blackcolor];
FRAME.ORIGIN.Y = 0;
[UIView animatewithduration:mmmessageduration animations:^{
Window_.frame = frame;
}];
}
+ (void) ShowMessage: (NSString *) msg Image: (UIImage *) image
{
[Timer_ invalidate];
Add button
UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];
[Button Setimage:image Forstate:uicontrolstatenormal];
[Button settitle:msg Forstate:uicontrolstatenormal];
Button.titleLabel.font = Mmfont;
if (image) {
Button.titleedgeinsets = Uiedgeinsetsmake (0, 10, 0, 0);
}
Button.frame = Window_.bounds;
[Window_ Addsubview:button];
Timer_ = [Nstimer scheduledtimerwithtimeinterval:mmmessageduration target:self selector: @selector (hide) Userinfo:nil Repeats:no];
}
+ (void) Hide
{
[UIView animatewithduration:mmmessageduration animations:^{
CGRect frame = window_.frame;
FRAME.ORIGIN.Y =-frame.size.height;
Window_.frame = frame;
} completion:^ (BOOL finished) {
Window_ = nil;
Timer_ = nil;
}];
}
+ (void) ShowMessage: (NSString *) msg
{
[Self showmessage:msg image:nil];
}
+ (void) showsuccess: (NSString *) msg
{
[Self showmessage:msg image:[uiimage imagenamed:@ "Check"];
}
+ (void) ShowError: (NSString *) msg
{
[Self showmessage:msg image:[uiimage imagenamed:@ "Fault"];
}
+ (void) showloading: (NSString *) msg
{
[Timer_ invalidate];
Timer_ = nil;
[Self Setupwindow];
UILabel *label = [[UILabel alloc]init];
Label.font = Mmfont;
Label.frame = Window_.bounds;
Label.textalignment = Nstextalignmentcenter;
Label.text = msg;
Label.textcolor = [Uicolor Whitecolor];
[Window_ Addsubview:label];
Load Circle
Uiactivityindicatorview *loadview = [[Uiactivityindicatorview alloc]initwithactivityindicatorstyle: Uiactivityindicatorviewstylewhite];
[Loadview startanimating];
CGFloat MSGW = [MSG sizewithattributes:@{nsfontattributename:mmfont}].width;
CGFloat centx = (WINDOW_.FRAME.SIZE.WIDTH-MSGW) *0.5-20;
CGFloat centy = window_.frame.size.height*0.5;
Loadview.center = Cgpointmake (Centx, Centy)
;
[Window_ Addsubview:loadview];
}
@end
To implement a cue box effect by customizing the window