Form button options in IOS Uiactionsheet commonly used methods to organize _ios

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.