To implement a cue box effect by customizing the window

Source: Internet
Author: User
Tags uikit

#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

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.