This article examples for you to share the iOS custom Alertview prompt box, first above, the frame background color, the button background color, prompts the message the font color can change
Using a single example to implement a rich custom interface
//PBAlertController.h
//Pbalertdemo////
Created by
Pepopo on 16/4/20.
COPYRIGHT©2016 year Pepopo. All rights reserved.
#import <UIKit/UIKit.h>
typedef void (^pbblock) ();
@interface pbalertcontroller:uiviewcontroller
/** set alertview background Color
* * * @property (nonatomic, copy) Uicolor * Alertbackgroundcolor;
/** Setting button Background color * * *
@property (nonatomic, copy) Uicolor *btnconfirmbackgroundcolor;
/** set Cancel button background color *
/@property (nonatomic, copy) Uicolor *btncancelbackgroundcolor;
/** Set Message font color
/@property (nonatomic, copy) Uicolor *messagecolor;
/** Create a single case * *
+ (instancetype) Sharealertcontroller;
/** Eject Alertview and click OK callback block
/-(void) Alertviewcontrollerwithmessage: (NSString *) message Andblock: (Pbblock) Block;
@end
Initialize the control in the. m file and lazily load the properties of the Alertview control to determine the initial color.
PBALERTCONTROLLER.M//Pbalertdemo////Created by Pepopo on 16/4/20. COPYRIGHT©2016 year Pepopo.
All rights reserved. #import "PBAlertController.h"/** screen size */#define Kmainscreenbounds [UIScreen mainscreen].bounds @interface PBALERTC
Ontroller ()/** Mask */@property (nonatomic, strong) UIView *coverview;
/** Bomb frame/@property (nonatomic, strong) UIView *alertview;
/** Click to determine the callback block */@property (nonatomic, copy) Pbblock block;
@end @implementation Pbalertcontroller-(void) viewdidload {[Super viewdidload];
Self.view.backgroundColor = [Uicolor Whitecolor];
}-(void) Alertviewcontrollerwithmessage: (NSString *) message Andblock: (pbblock) block{self.block = block;
Create Mask UIView * Coverview = [[UIView alloc] initwithframe:kmainscreenbounds];
Self.coverview = Coverview;
[Self.view Addsubview:coverview];
Coverview.backgroundcolor = [Uicolor blackcolor];
Coverview.alpha = 0.7;
Create a hint box view UIView * Alertview = [[UIView alloc] init]; Alertview.backgroundcolor = SELF.ALertbackgroundcolor;
Set Fillet radius AlertView.layer.cornerRadius = 6.0;
Self.alertview = Alertview;
[Self.view Addsubview:alertview];
Alertview.center = Coverview.center;
Alertview.bounds = CGRectMake (0, 0, kMainScreenBounds.size.width * 0.75, kMainScreenBounds.size.width * 0.75 * 1.5/3);
Create action hint Label Uilabel * label = [[Uilabel alloc] init];
[Alertview Addsubview:label];
Label.text = @ "Action prompt";
Label.font = [Uifont systemfontofsize:19];
Label.textalignment = Nstextalignmentcenter;
CGFloat lblwidth = alertView.bounds.size.width;
CGFloat lblhigth = 22;
Label.frame = CGRectMake (0, 0, lblwidth, lblhigth);
Create intermediate Gray Split line UIView * separateline = [[UIView alloc] init];
Separateline.backgroundcolor = [Uicolor Graycolor];
[Alertview Addsubview:separateline];
Separateline.frame = CGRectMake (0, Lblhigth + 1, alertView.bounds.size.width, 1);
Create a message label Uilabel * lblmessage = [[Uilabel alloc] init];
Lblmessage.textcolor = Self.messagecolor; [Alertview Addsubview:lblmesSAGE];
Lblmessage.text = message;
Lblmessage.textalignment = Nstextalignmentcenter; Lblmessage.numberoflines = 2;
Displays up to two lines of message cgfloat margin = 5;
CGFloat MSGX = margin;
CGFloat msgy = lblhigth + 3;
CGFloat MSGW = alertview.bounds.size.width-2 * margin;
CGFloat MSGH = 44;
Lblmessage.frame = CGRectMake (MSGX, Msgy, MSGW, MSGH);
Create OK Cancel button cgfloat buttonwidth = (alertview.bounds.size.width-4 * margin) * 0.5;
CGFloat buttonhigth = 25;
UIButton * Btncancel = [[UIButton alloc] init];
[Alertview Addsubview:btncancel];
[Btncancel Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
[Btncancel settitle:@ "Cancel" forstate:uicontrolstatenormal];
[Btncancel SetBackgroundColor:self.btnCancelBackgroundColor];
Btncancel.frame = CGRectMake (margin, alertview.bounds.size.height-margin-buttonhigth, buttonwidth, buttonHigth);
Btncancel.tag = 0;
[Btncancel addtarget:self Action: @selector (didclickbtnconfirm:) forcontrolevents:uicontroleventtouchupinside];
OK button UIButton * btnconfirm = [[UIButton alloc] init];
Btnconfirm.tag = 1;
[Alertview addsubview:btnconfirm];
[Btnconfirm Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
[Btnconfirm settitle:@ "determine" forstate:uicontrolstatenormal];
[Btnconfirm SetBackgroundColor:self.btnConfirmBackgroundColor]; Btnconfirm.frame = CGRectMake (Alertview.bounds.size.width-margin-buttonwidth, Alertview.bounds.size.height-margin
-Buttonhigth, Buttonwidth, buttonhigth);
[Btnconfirm addtarget:self Action: @selector (didclickbtnconfirm:) forcontrolevents:uicontroleventtouchupinside]; /** Click OK or Cancel trigger event/-(void) Didclickbtnconfirm: (UIButton *) sender{if (Sender.tag = 0) {[Self Dismissviewcontrol
Leranimated:yes Completion:nil];
Return
} self.block ();
[Self dismissviewcontrolleranimated:yes completion:nil];
}-(void) didreceivememorywarning {[Super didreceivememorywarning];}
Static Pbalertcontroller * instance = nil; + (instancetype) sharealertcontroller{static DISPATCh_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{instance = [[Pbalertcontroller alloc] init];
});
return instance; }-(Uicolor *) alertbackgroundcolor{if (_alertbackgroundcolor = = nil) {_alertbackgroundcolor = [Uicolor colorWithRed
: 249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
return _alertbackgroundcolor; /** OK button Background color * *-(Uicolor *) btnconfirmbackgroundcolor{if (_btnconfirmbackgroundcolor = = nil) {_btnconfirmbackgroun
Dcolor = [Uicolor Orangecolor];
return _btnconfirmbackgroundcolor; /** Cancel button Background color * *-(Uicolor *) btncancelbackgroundcolor{if (_btncancelbackgroundcolor = = nil) {_btncancelbackgroundco
Lor = [Uicolor Bluecolor];
return _btncancelbackgroundcolor;
/** Message Font Color */-(Uicolor *) messagecolor{if (_messagecolor = = nil) {_messagecolor = [uicolor blackcolor];
return _messagecolor;
} @end
Call where it needs to be called.
//VIEWCONTROLLER.M
//Pbalertdemo////
Created by
Pepopo on 16/4/20.
COPYRIGHT©2016 year Pepopo. All rights reserved.
#import "ViewController.h"
#import "PBAlertController.h"
@interface viewcontroller ()
@end
@implementation Viewcontroller
//Click button pop-up Prompt box
-(ibaction) CLICKSHOWALERTBTN: (ID) Sender {
Pbalertcontroller * ALERTVC = [Pbalertcontroller Sharealertcontroller];
Alertvc.messagecolor = [Uicolor redcolor];
[ALERTVC alertviewcontrollerwithmessage:@ "This is a message Sheikh" andblock:^{
NSLog (@ "Click OK to execute the method");
Alertvc.modaltransitionstyle = Uimodaltransitionstylecrossdissolve;
[Self PRESENTMODALVIEWCONTROLLER:ALERTVC animated:yes];
}
@end
The above is the entire content of this article, I hope to learn about iOS program design help.