[Code Note] iOS-custom alertView, ios-custom alertview
I ,.
Ii. Code.
ViewController. h
#import
ViewController. m
# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // background color self. view. backgroundColor = [UIColor redColor]; // Add the b
IOS custom alertView, inherited from UIView, you can add a subview, title image + Text
Custom alertView, inherited from UIView, you can add a subview in the message area: addCustomerSubviewThe title can contain images and text. Only two buttons are supported.
//-Call the alertView show method on the Controller that requires alert
CustomAlertView *
IOS custom alertView, inherited from UIView, you can add a subview, title image + text,
Custom alertView, inherited from UIView, you can add a subview in the message area: addCustomerSubviewThe title can contain images and text. Only two buttons are supported.
//-Call the alertView show method on the Controller that requires alert
CustomAlertView *
Transferred from: http://blog.it985.com/4321.htmlAlertview is the pop-up window notification box that comes with iOS, let's look at the default styleDirectly below the code
12345
- (void)delete{//弹窗UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"是否删除?"message:nil delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];[alertView show];}
If you want to
Ns_class_available_ios (2_0) @ interface uialertview: uiview {
From the definition of uialertview, we can see that uialertview is also a subclass of uiview and is defined in Versions later than ios2.0.
The following is an example of its definition:
-(Id) initWithTitle :( NSString *) title
Message :( NSString *) message
Delegate :( id/*
CancelButtonTitle :( NSString *) cancelButtonTitle
OtherButtonTitles :( NSString *) otherButtonTitles,..., nil;
Initialize a uialertview, and specify the title,
Use of AlertView + Block, alertviewblock
AlertView is frequently used. It seems that it is not so ugly After flattening, but so far, the official website still uses Delegate to handle click events, which affects the readability of the program.
If Block is used, it will be clear at a glance. I wanted to write one, but it was too lazy (in fact, it's not okay ....).
Of course, the omnipotent Git is certainly a
Specific code at the end of the article. Show me how to use it first. The situation of Alertview - (void) Creatalertview{uialertview*alertview=[[uialertview alloc]initwithtitle:@ "title" message:@ "Message" delegate:selfcancelbuttontitle:@ " Cancel "otherbuttontitles:@" OK ", nil];[alertviewshow];} #pragma markUIAlertViewDelegate- (void) Alertview: (uialertview*)
Alert views are pop-up views that appear over the current view on the iPhone.
Creating and showing an alert (ARC compatible ):
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Really reset? "Message: @" Do you really want to reset this game? "Delegate: self cancelButtonTitle: @" Cancel "otherButtonTitles: nil];// Optional-add more buttons:[Alert addButtonWithTitle: @ "Yes"];[Alert show];For non-ARC (retain/release) projects, you must autorelease the alert view:
UIAlertView * alert =
How to write a custom AlertviewEffectDescriptionConsidering the subsequent customization and maintainability, I have defined the base class of Alertview abstraction with Abstractalertview, which is accomplished by subclasses.Note: This is just a rough write of an implementation, and does not take into account the rationality of the Code and accuracy.SourceHttps://github.com/YouXianMing/AbstractAlertView////AbstractAlertView.h//Alertviewdemo////Created
After the show method of alertview is executed, the subsequent code will continue to run, instead of waiting for the user to press the key to finish. In this way, if the pop-up code is written in a bool function, the solution is as follows:
-(Bool) beforebackbuttonclickevent {uialertview * Alert = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "Discard Process? "Delegate: Self cancelbuttontitle: @" no "otherbuttontitles: @" yes ", nil]; [a
After the show method of alertview is executed, the subsequent code will continue to run, instead of waiting for the user to press the key to finish. In this way, if the pop-up code is written in a bool function, the solution is as follows:
1-(bool) beforebackbuttonclickevent {2 uialertview * Alert = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "Discard Process? "Delegate: Self cancelbuttontitle: @" no "otherbuttontitles: @" yes ", nil];
In Windows applications, you often use the model dialog box to interact with users, such as the logon box.In IOS apps, we sometimes want to do the same thing. However, in the ios ui library, there is no modal dialog box, and what is closest to that is alertview.But with alertview only, we can only make text prompts, rather than interacting with users.
This article describes how to customize the mode Dialog Box Based on
In Windows applications, you often use the model dialog box to interact with users, such as the logon box.In IOS apps, we sometimes want to do the same thing. However, in the ios ui library, there is no modal dialog box, and what is closest to that is alertview.But with alertview only, we can only make text prompts, rather than interacting with users.
This article describes how to customize the mode Dialog Box Based on
Create a bullet boxUialertview *alert = [[Uialertview alloc] initwithtitle:@ "title" message:@ "Show Details" Delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitle:@ "OK", nil];Set the display type of alert (this is when message is nil, enter the message content)Alert.alertviewstyle = Uialertviewstyleplaintextinput;Set the contents of the text box inputNSString *text;[Alert textfiledatindex:0].text = text;Show Alert Bullet Box[Alert show];#pragma Mark-uialertview Proxy methodClicking on th
Sometimes we need a frame to confirm or return when we do the operation, which is alertview. In the previous project, when we clicked the Stop button, the pop-up window was confirmed. Pop-up window This action occurs when we click the Stop button, so the Alertview code is added to the Stop button action, the code is as follows:@IBAction func Stopbutton (Sender:uibutton) {let stopdownloadconfi
- (void) Showtextfielduialertview{Uialertview*alertview = [[UialertviewAlloc]Initwithtitle:@"Please enter the amount of consumption"Message:NilDelegate:SelfCancelbuttontitle:@"Cancel"Otherbuttontitles:@"Are you sure",Nil];Alertview.Alertviewstyle=Uialertviewstyleplaintextinput;[[AlertviewTextfieldatindex:0]Setkeyboardtype:Uikeyboardtypenumberpad];[AlertviewShow];}- (void) Alertview: (Uialertview*)
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.