Many times the product has a demand, to prompt box, prompt box prompt box!!! The system is too ugly, (ーー゛) me a. Let the UI give a standard I do O (╯-╰) o
In fact, it's easy to make it disappear in a variety of animations as required.
command+ N Creates a UIView class, named Awpopview
AWPopView.h file
Cancel button click event
typedef void (^cancelblock) ();
Determining button Click events
typedef void (^sureblock) ();
@interface Awpopview:uiview
@property (nonatomic,copy) Cancelblock Cancel_block;
@property (nonatomic,copy) Sureblock Sure_block;
/**
* Simple ISBN: Ios_, Wei http://www.cnblogs.com/chenwei-dcav/
*
* @param title
* @param content
* @param sure OK button content
* @param sureblock OK button click event
*
* @return Szkalterview
*/
+ (Instancetype) Alterviewwithtitle: (NSString *) title
Content: (NSString *) content
Sure: (NSString *) sure
Surebtclcik: (Sureblock) Sureblock;
AWPOPVIEW.M file
#define WIDTH [UIScreen mainscreen].bounds.size.width
#define HEIGHT [UIScreen mainscreen].bounds.size.height
@interface Awpopview ()
@property (Nonatomic,retain) UIView *alterview;
@property (Nonatomic,retain) UILabel *titlelb;
@property (Nonatomic,retain) UILabel *contentlb;
@property (Nonatomic,retain) UIButton *surebt;
@property (nonatomic,copy) NSString *title;
@property (nonatomic,copy) NSString *content;
@property (nonatomic,copy) NSString *cancel;
@property (nonatomic,copy) NSString *sure;
@end
@implementation Awpopview
-(Instancetype) initWithFrame: (CGRect) frame
{
Self=[super Initwithframe:frame];
if (self) {
Title
_titlelb=[[uilabel alloc]initwithframe:cgrectmake (0, 0, Self.bounds.size.width, 15)];
_titlelb.textcolor=setcolor (111, 208, 199);
_titlelb.font = [Uifont systemfontofsize:16];
_titlelb.adjustsfontforcontentsizecategory = YES;
[Self addsubview:_titlelb];
_titlelb.sd_layout.leftspacetoview (self, 22.5). Topspacetoview. Widthis (+). Heightis (15);
Content
_contentlb=[[uilabel alloc]initwithframe:cgrectmake (0, Cgrectgetmaxy (_titlelb.frame) +, Self.bounds.size.width, 15)];
_contentlb.font = [Uifont systemfontofsize:15];
[Self addsubview:_contentlb];
_contentlb.sd_layout.leftspacetoview (self, 22.5). Topspacetoview (_titlelb, +). Widthis (Self.bounds.size.width). Heightis (15);
OK button
_surebt=[[uibutton Alloc]initwithframe:cgrectmake (SELF.BOUNDS.SIZE.WIDTH/2, Cgrectgetmaxy (_contentLb.frame), 120, 40)];
_surebt.centerx = Self.centerx;
_surebt.layer.cornerradius = 5;
_surebt.layer.maskstobounds = YES;
_surebt.backgroundcolor = SetColor (111, 208, 199);
[_surebt Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
[_surebt addtarget:self Action: @selector (Surebtclick) forcontrolevents:uicontroleventtouchupinside];
[Self addsubview:_surebt];
_surebt.sd_layout.leftspacetoview (self, (self.bounds.size.width-120)/2). Bottomspacetoview. WidthIs (120) . Heightis (40);
}
return self;
}
#pragma mark----Implementing class methods
+ (Instancetype) Alterviewwithtitle: (NSString *) title
Content: (NSString *) content
Sure: (NSString *) sure
Surebtclcik: (Sureblock) Sureblock;
{
Awpopview *alterview=[[awpopview alloc]initwithframe:cgrectmake (0, 0, 345, 200)];
Alterview.backgroundcolor=[uicolor Whitecolor];
Alterview.center=cgpointmake (WIDTH/2, HEIGHT/2 +20);
alterview.layer.cornerradius=5;
Alterview.layer.maskstobounds=yes;
Alterview.title=title;
Alterview.content=content;
Alterview.sure=sure;
Alterview.sure_block=sureblock;
return alterview;
}
#pragma mark--a value to a property
-(void) Settitle: (NSString *) title
{
_titlelb.text=title;
}
-(void) SetContent: (NSString *) content
{
_contentlb.text=content;
}
-(void) Setsure: (NSString *) sure
{
[_surebt settitle:sure Forstate:uicontrolstatenormal];
}
#pragma mark----OK button click event
-(void) Surebtclick
{
[Self removefromsuperview];
Self.sure_block ();
}
The class is finished, and the exciting moment is up, so that he disappears from any viewcontroller.
VIEWCONTROLLER.M file
Add a light black background, the pop-up box is not clickable anywhere else
UIWindow * window = [[UIApplication Sharedapplication]keywindow];
UIView * Blackview = [[UIView alloc]init];
Blackview.backgroundcolor = [[Uicolor blackcolor]colorwithalphacomponent:0.4];
[Window Addsubview:blackview];
BlackView.sd_layout.leftSpaceToView (window, 0). Topspacetoview (window, 0). Rightspacetoview (window, 0). Bottomspacetoview (window, 0);//Good fit
Awpopview *lll=[awpopview alterviewwithtitle:@ "System Prompt" content:@ "requires re-login" sure:@ "OK" surebtclcik:^{
Blackview.alpha = 0.0f;
Loginviewcontroller * login = [[Loginviewcontroller alloc]init];
[Self.navigationcontroller Pushviewcontroller:login Animated:yes];
}];
[Window addsubview:lll];
Direct class method creation, is so sou eaey. Box inside the button title can go to class inside casually add, if feel not enough fun iOS sister can add QQ 751045314, Ah Wei don't mind our deep communication Oh, to demo leave QQ email
IOS Package Global Prompt box