iOS no sister project-Package status bar indicator (UIWindow implementation)

Source: Internet
Author: User
Tags uikit

I. Header file

1 #import<UIKit/UIKit.h>2 3 @interfaceChaosstatusbarhud:nsobject4 /** Show Success Information*/5+ (void) Showsuccess: (NSString *) str;6 /** Display failure Information*/7+ (void) ShowError: (NSString *) str;8 /** Displays the information being loaded*/9+ (void) Showloading: (NSString *) str;Ten /** Hide*/ One+ (void) Hide; A /** Show Plain text*/ -+ (void) ShowMessage: (NSString *) str; - /** Custom Icon text*/ the+ (void) ShowMessage: (NSString *) str withimage: (UIImage *) image; - @end

Two. Implement the. m file

1 #import "ChaosStatusBarHUD.h"2 3 #defineCHAOSWINDOWH 204 #defineChaosscreenw [UIScreen mainscreen].bounds.size.width5 6 @implementationChaosstatusbarhud7 8 StaticNstimer *Timer_;9 StaticUIWindow *Window_;Ten  One  A+ (void) ShowWindow - { -     //first stop the timer before the [Timer_ invalidate]; -UIWindow *window =[[UIWindow alloc] init]; -Window.backgroundcolor =[Uicolor Blackcolor]; -Window.windowlevel =Uiwindowlevelstatusbar; +Window.hidden =NO; -Window_ =window; +Window.frame = CGRectMake (0, -chaoswindowh, Chaosscreenw, CHAOSWINDOWH); A      at     //animation effects -[UIView animatewithduration:0.25animations:^{ -          -Window.frame = CGRectMake (0,0, Chaosscreenw, CHAOSWINDOWH); -     }]; - } in /** Custom Icon text*/ -+ (void) ShowMessage: (NSString *) str withimage: (UIImage *) Image to { +     //Create a form - [self ShowWindow]; the     //Add button *UIButton *button =[[UIButton alloc] init]; $Button.frame =window_.bounds;Panax Notoginseng [button Setimage:image forstate:uicontrolstatenormal]; - [button Settitle:str forstate:uicontrolstatenormal]; theButton.titleedgeinsets = Uiedgeinsetsmake (0, -,0,0); +Button.titleLabel.font = [Uifont systemfontofsize: -]; A [Window_ Addsubview:button]; the      +     //end animation after two seconds -Timer_ = [Nstimer scheduledtimerwithtimeinterval:2.0target:self selector: @selector (hide) userinfo:nil repeats:no]; $ } $  - /** Show Plain text*/ -+ (void) ShowMessage: (NSString *) Str the { - [self showmessage:str withimage:nil];Wuyi } the  - /** Show Success Information*/ Wu+ (void) Showsuccess: (NSString *) Str - { About[Self showmessage:str withimage:[uiimage imagenamed:@"Success"]]; $ } -  - /** Display failure Information*/ -+ (void) ShowError: (NSString *) Str A { +[Self showmessage:str withimage:[uiimage imagenamed:@"Error"]]; the } -  $ /** Displays the information being loaded*/ the+ (void) Showloading: (NSString *) Str the { the     //Stop Timer the [Timer_ invalidate]; -Timer_ =Nil; in     //Create Window the [self ShowWindow]; the     //Add button AboutUIButton *button =[[UIButton alloc] init]; theButton.frame =window_.bounds; the [button Settitle:str forstate:uicontrolstatenormal]; theButton.titleLabel.font = [Uifont systemfontofsize: -]; + [Window_ Addsubview:button]; -     //calculate button Text width theCGFloat titlewidth = [str sizewithattributes:@{nsfontattributename: [Uifont systemfontofsize: -]}].width;Bayi     //calculate the x value of Chrysanthemums theCGFloat x = (Chaosscreenw-2* titlewidth) *0.5; the     //calculates the Y value of a loadingview -CGFloat y = window_.frame.size.height *0.5; -Uiactivityindicatorview *loadingview =[[Uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhite]; the [Loadingview startanimating]; the [Window_ Addsubview:loadingview]; theLoadingview.center =cgpointmake (x, y); the } -  the /** Hide*/ the+ (void) Hide the {94     //animation effects the[UIView animatewithduration:0.25animations:^{ the          theWindow_.frame = CGRectMake (0, - -, Chaosscreenw, CHAOSWINDOWH);98} completion:^(BOOL finished) { About          -Timer_ =Nil;101Window_ =Nil;102     }];103 }104 @end

iOS no sister project-Package status bar indicator (UIWindow implementation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.