What is an action form? Look at the picture:
A look at the picture is clear, do not need to say more.
Copy Code code as follows:
uiactionsheet* mysheet = [[Uiactionsheet alloc]
initwithtitle:@ "Actionchoose"
Delegate:self
cancelbuttontitle:@ "Cancel"
destructivebuttontitle:@ "Destroy"
otherbuttontitles:@ "OK", nil];
[MySheet ShowInView:self.view];
Like Uialertview, we also handle the action of pressing the button in the delegate method. Remember to add uiactionsheetdelegate to the class you are entrusting.
Copy Code code as follows:
-(void) Actionsheetcancel: (Uiactionsheet *) actionsheet{
//
}
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex{
//
}
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (Nsinteger) buttonindex{
//
}
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Willdismisswithbuttonindex: (Nsinteger) buttonindex{
//
}
See that red button? It is a so-called destruction button supported by Actionsheet, which acts as a warning to a certain action.
For example, permanently delete a message or log. If you specify a Destroy button, he will highlight it in red:
Copy Code code as follows:
Mysheet.destructivebuttonindex=1;
Like the navigation bar, the action form also supports three styles:
Copy Code code as follows:
Uiactionsheetstyledefault//Default style: White text appears on gray background
Uiactionsheetstyleblacktranslucent//Transparent black background, white text
Uiactionsheetstyleblackopaque//Black background, white text
Usage use case:
Copy Code code as follows:
Mysheet.actionsheetstyle = Uiactionsheetstyleblackopaque;
Common Methods and properties
Show Actionsheet Method:
1. Display inside a view, you can use the Showinview
Copy Code code as follows:
[MySheet showinview:self];
2. If you want to align Actonsheet with toolbars or tab bars, you can use Showfromtoolbar or Showfromtabbar
Copy Code code as follows:
[MySheet Showfromtoolbar:toolbar];
[MySheet Showfromtabbar:tabbar];
To cancel an action form
After the user presses the button, the Actionsheet disappears-unless the application has a special reason, the user is pressed to make a button. Use the dismiss method to make the form disappear:
Copy Code code as follows:
[MySheet dismisswithclickbuttonindex:1 Animated:yes];
@property (nonatomic,copy) NSString *title;
Set Title
Copy Code code as follows:
@property (nonatomic) Uiactionsheetstyle Actionsheetstyle;
Add a button that returns the index of the button
Copy Code code as follows:
-(Nsinteger) Addbuttonwithtitle: (NSString *) title;
[/code]
Get Button Caption
Copy Code code as follows:
-(NSString *) Buttontitleatindex: (Nsinteger) Buttonindex;
Get the number of buttons
Copy Code code as follows:
@property (nonatomic,readonly) Nsinteger numberofbuttons;
Set the index value of the Cancel button
Copy Code code as follows:
@property (nonatomic) Nsinteger Cancelbuttonindex;
Set Special tags
Copy Code code as follows:
@property (nonatomic) Nsinteger Destructivebuttonindex;
Whether the view is currently visible
Copy Code code as follows:
@property (nonatomic,readonly,getter=isvisible) BOOL visible;
Here are a few pop-up ways to show different ways depending on the style:
Copy Code code as follows:
-(void) Showfromtoolbar: (Uitoolbar *) view;
-(void) Showfromtabbar: (Uitabbar *) view;
-(void) Showfrombarbuttonitem: (Uibarbuttonitem *) Item animated: (BOOL) animated;
-(void) Showfromrect: (cgrect) rect inview: (UIView *) View animated: (BOOL) animated;
-(void) Showinview: (UIView *) view;
Use code to retract views
Copy Code code as follows:
-(void) Dismisswithclickedbuttonindex: (Nsinteger) Buttonindex animated: (BOOL) animated;
Uiactionsheet Proxy method
Copy Code code as follows:
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) Buttonindex;
How to trigger when clicking a button
Copy Code code as follows:
-(void) Willpresentactionsheet: (Uiactionsheet *) Actionsheet;
The method to trigger when the view will pop up
Copy Code code as follows:
-(void) Didpresentactionsheet: (Uiactionsheet *) Actionsheet;
Methods that the view has already popped trigger
Copy Code code as follows:
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Willdismisswithbuttonindex: (Nsinteger) Buttonindex;
The method that triggers when the view is to retract when the button is clicked
Copy Code code as follows:
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (Nsinteger) Buttonindex;
The method that triggers when the view has been retracted when the button is clicked