iOS Development-uiactionsheet Simple Introduction

Source: Internet
Author: User

Uiactionsheet and Uialertview are both modal views of the iOS system, and an important feature of modal views is the ability to block the event response of other views when the modal view is displayed. In general, we use more of the Uialertview, Uiactionsheet relatively less, and occasionally as a pull-down menu to display is very useful. Typically, if you display a modal view, you can customize a uiviewcontroller, but the content and animations in it work quite a lot.

Uiactionsheet Introduction

Before you introduce uiactionsheet, you need to look at the effect of a simple implementation:

This is the most basic Uiactionsheet, title and button, but sometimes for beauty can not use the title, the effect seems to be very good, first on the code after the explanation:

  Uiactionsheet *actionsheet = [[Uiactionsheet alloc]                                      initwithtitle:@ "blog Park"                                      delegate:self                                      cancelbuttontitle:@ "Cancel"                                      destructivebuttontitle:@ "OK"                                      otherbuttontitles:@ "Keso", @ "Flyelephant", nil];        Actionsheet.actionsheetstyle = Uiactionsheetstyleblackopaque;        [Actionsheet ShowInView:self.view];

We can clearly feel that the white red word, the other button is the white bottom blue word, because determine here is Destructivebutton, equivalent to destroy is to give the user an obvious hint, here the display is directly in the view display, of course, there are other places to display, the call method is as follows:

-(void) Showfromtoolbar: (Uitoolbar *) view;-(void) Showfromtabbar: (Uitabbar *) view;-(void) Showfrombarbuttonitem: ( Uibarbuttonitem *) Item animated: (BOOL) animated Ns_available_ios (3_2);-(void) Showfromrect: (cgrect) rect InView: ( UIView *) View animated: (BOOL) animated Ns_available_ios (3_2);-(void) Showinview: (UIView *) view;

With most controls, Uiactionsheet also has proxies that implement Uiactionsheetdelegate to perform the events that you need to perform after the button:

-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) buttonindex{NSString *re[email     protected] "";            Switch (buttonindex) {case 0: [email protected] "OK";        Break            Case 1: [email protected] "Keso";        Break            Case 2: [email protected] "flyelephant";        Break            Case 3: [email protected] "Cancel";    Break } uialertview *alertview=[[uialertview alloc]initwithtitle:@ "test" Message:result delegate:self cancelButtonTitle:@ "OK    [Otherbuttontitles:nil]; [Alertview show];} -(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (nsinteger) buttoninde{NSLog (@ " Diddismisswithbuttonindex-flyelphant ");} -(void) Actionsheet: (Uiactionsheet *) Actionsheet Willdismisswithbuttonindex: (nsinteger) buttonindex{NSLog (@ " Willdismisswithbuttonindex-flyelphant ");} -(void) Actionsheetcancel: (Uiactionsheet *) actionsheet{NSLog (@ "HomE key to execute this method "); 

Four methods are more common use, generally only need to call the first method, Actionsheetcancel Online said less, this method is generally clicked when the home button execution, not click cancel button execution, details can refer to the document explanation:

Called when we cancel a view (eg the user clicks the Home button). This isn't called when the user clicks the Cancel button.//If isn't defined in the delegate, we simulate a click in the CA Ncel button

Uiactionsheet style default style, black translucent and black opaque three styles:

typedef ns_enum (Nsinteger, Uiactionsheetstyle) {    uiactionsheetstyleautomatic        =-1,       //Take appearance From toolbar style otherwise uses ' default '    uiactionsheetstyledefault          = Uibarstyledefault,    Uiactionsheetstyleblacktranslucent = uibarstyleblacktranslucent,    uiactionsheetstyleblackopaque      = Uibarstyleblackopaque,};

  If you feel the system is uncomfortable, can be customized, completely depends on individual needs ~

iOS Development-uiactionsheet Simple Introduction

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.