Prompt box (warning box) control 2:uiactionsheet
Features: when clicking on a button or a label, pop up a prompt, display the necessary hints, and then complete the desired function by adding a button. It is similar to the navigation bar, and it inherits from UIView. Style Type:
typedef ns_enum (Nsinteger, Uiactionsheetstyle) {
uiactionsheetstyleautomatic =-1, //ios System auto Default style
Uiactionsheetstyledefault = Uibarstyledefault, //default style, white text on gray background
Uiactionsheetstyleblacktranslucent = uibarstyleblacktranslucent //Transparent black background, white text
Uiactionsheetstyleblackopaque = Uibarstyleblackopaque, //black background, white text
};
Property:
@property (nonatomic,assign) id<uiactionsheetdelegate> delegate; //Agent
@property (nonatomic,copy) NSString *title; //Title
@property (nonatomic) Uiactionsheetstyle Actionsheetstyle; //Style type
@property (nonatomic,readonly) Nsinteger numberofbuttons; //Button Count
@property (nonatomic) Nsinteger Cancelbuttonindex; //Cancel the index of the button
@property (nonatomic) Nsinteger Destructivebuttonindex; //red Button index
@property (nonatomic,readonly) Nsinteger Firstotherbuttonindex; //Other First button index
@property (nonatomic,readonly,getter=isvisible) BOOL visible; //Is visible
Method:
※ initialization method for creating an instance
-(Instancetype) Initwithtitle: (NSString *) title delegate: (id<uiactionsheetdelegate>) delegate Cancelbuttontitle: (NSString *) cancelbuttontitle destructivebuttontitle: (NSString *) destructivebuttontitle Otherbuttontitles: (NSString *) Otherbuttontitles, ... ("Use Uialertcontroller instead.");
※ Add a button to return its index
-(Nsinteger) Addbuttonwithtitle: (NSString *) title;
※ Returns the button text for the specified index
-(NSString *) Buttontitleatindex: (Nsinteger) Buttonindex;
※ displayed on the toolbar
-(void) Showfromtoolbar: (Uitoolbar *) view;
※ displayed in the navigation bar
-(void) Showfromtabbar: (Uitabbar *) view;
※ displayed on the toolbar button
-(void) Showfrombarbuttonitem: (Uibarbuttonitem *) Item animated: (BOOL) animated;
※ display on the specified area and view
-(void) Showfromrect: (cgrect) rect inview: (UIView *) View animated: (BOOL) animated;
※ Display on the view
-(void) Showinview: (UIView *) view;
※ Button Disappears
-(void) Dismisswithclickedbuttonindex: (Nsinteger) Buttonindex animated: (BOOL) animated;
Proxy method:
@protocol uiactionsheetdelegate <NSObject>
@optional
How to trigger when a button is clicked
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) Buttonindex;
If there is no defined delegate, we simulate a click cancel button
-(void) Actionsheetcancel: (Uiactionsheet *) Actionsheet;
The party that is triggered when the warning box will be displayed
-(void) Willpresentactionsheet: (Uiactionsheet *) Actionsheet;
The method that is triggered when the cue box is already displayed
-(void) Didpresentactionsheet: (Uiactionsheet *) Actionsheet;
method to trigger when the cue box is going to disappear
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Willdismisswithbuttonindex: (Nsinteger) Buttonindex;
Method triggered when the cue box has disappeared
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (Nsinteger) Buttonindex;
@end
Examples are: class implementation protocol
@interface Viewcontroller () <UIActionSheetDelegate>
1.//Instantiation
// Create a Cue box instance Uiactionsheet *actionsheet = [[Uiactionsheet alloc]initwithtitle:@ 'title'delegate : Self cancelbuttontitle:@ "cance" destructivebuttontitle:@ " Destructive" otherbuttontitles:@"button1"@ " Button2", nil];
2.//Set Style
// Set style Actionsheet.actionsheetstyle = uiactionsheetstyleblacktranslucent;
3.//Set up proxy
// set up proxy Actionsheet. delegate = self;
4.//display on the view
// Show on view [Actionsheet ShowInView:self.view];
To implement the Proxy method:
#pragma mark-<uiactionsheetdelegate>
1. Trigger an event when the button is clicked
// the method that fires when a button is clicked -(void) Actionsheet: (Uiactionsheet *) actionsheet Clickedbuttonatindex: ( Nsinteger) buttonindex{ NSLog (@ "actionsheet:clickedbuttonatindex:");}
2. Events triggered when the prompt box is canceled
// If there is no defined delegate, we simulate a click cancel button -(void) Actionsheetcancel: (Uiactionsheet *) actionsheet{ NSLog (@ "actionsheetcancel:");}
3. Event triggered when the cue box is about to be displayed
// the party to be triggered when the warning box is to be displayed -(void) Willpresentactionsheet: (Uiactionsheet *) actionsheet{ NSLog ( @" Willpresentactionsheet: " );}
4. The method that is triggered when the cue box is displayed
// method triggered when the cue box has been displayed -(void) Didpresentactionsheet: (Uiactionsheet *) actionsheet{ NSLog ( @ "didpresentactionsheet:");}
5. Method to trigger when the cue box is going to disappear
// method to trigger when the cue box is going to disappear -(void) Actionsheet: (Uiactionsheet *) actionsheet Willdismisswithbuttonindex: ( Nsinteger) buttonindex{ NSLog (@ "actionsheet:willdismisswithbuttonindex:" );}
6. How to trigger when the cue box disappears
// method triggered when the cue box has disappeared -(void) Actionsheet: (Uiactionsheet *) actionsheet Diddismisswithbuttonindex: ( Nsinteger) buttonindex{ NSLog (@ "actionsheet:diddismisswithbuttonindex:" );}
The demo results are as follows:
The proxy method calls are as follows:
When the program runs without clicking the button:
--29.647 :uiactionsheet[3866: 212744] Willpresentactionsheet:
When you click on any button:
-- the- - +: *:18.882Cue box uiactionsheet[3866:212744] Actionsheet:clickedbuttonatindex: -- the- - +: *:18.883Cue box uiactionsheet[3866:212744] Actionsheet:willdismisswithbuttonindex: -- the- - +: *:19.297Cue box uiactionsheet[3866:212744] Actionsheet:diddismisswithbuttonindex:
IOS: Hint Box (warning box) control Uiactionsheet