天天看點

IOS中UIActionSheet使用詳解

- (instancetype)initwithtitle:(nsstring *)title delegate:(id<uiactionsheetdelegate>)delegate cancelbuttontitle:(nsstring *)cancelbuttontitle destructivebuttontitle:(nsstring *)destructivebuttontitle otherbuttontitles:(nsstring *)otherbuttontitles, ...;

參數說明:

title:視圖示題

delegate:設定代理

cancelbuttontitle:取消按鈕的标題

destructivebuttontitle:特殊标記的按鈕的标題

otherbuttontitles:其他按鈕的标題

@property(nonatomic,copy) nsstring *title;

設定标題

@property(nonatomic) uiactionsheetstyle actionsheetstyle;

設定風格,枚舉如下:

<a href="http://my.oschina.net/u/2340880/blog/409907#">?</a>

1

2

3

4

5

6

<code>typedef</code> <code>ns_enum(nsinteger, uiactionsheetstyle) {</code>

<code>    </code><code>uiactionsheetstyleautomatic        = -1,      </code>

<code>    </code><code>uiactionsheetstyledefault          = uibarstyledefault,</code>

<code>    </code><code>uiactionsheetstyleblacktranslucent = uibarstyleblacktranslucent,</code>

<code>    </code><code>uiactionsheetstyleblackopaque      = uibarstyleblackopaque,</code>

<code>};</code>

- (nsinteger)addbuttonwithtitle:(nsstring *)title;

添加一個按鈕,會傳回按鈕的索引

- (nsstring *)buttontitleatindex:(nsinteger)buttonindex;

擷取按鈕标題

@property(nonatomic,readonly) nsinteger numberofbuttons;

擷取按鈕數量

@property(nonatomic) nsinteger cancelbuttonindex;

設定取消按鈕的索引值

@property(nonatomic) nsinteger destructivebuttonindex;

設定特殊标記

@property(nonatomic,readonly,getter=isvisible) bool visible;

視圖目前是否可見

下面是幾種彈出方式,會根據風格不同展現不同的方式

- (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;

- (void)dismisswithclickedbuttonindex:(nsinteger)buttonindex animated:(bool)animated;

使用代碼将視圖收回

- (void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex;

點選按鈕時觸發的方法

- (void)willpresentactionsheet:(uiactionsheet *)actionsheet; 

視圖将要彈出時觸發的方法

- (void)didpresentactionsheet:(uiactionsheet *)actionsheet;

視圖已經彈出式觸發的方法

- (void)actionsheet:(uiactionsheet *)actionsheet willdismisswithbuttonindex:(nsinteger)buttonindex;

點選按鈕後,視圖将要收回時觸發的方法

- (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex;

點選按鈕後,視圖已經收回時觸發的方法