iOS中的表單按鈕選項(xiàng)UIActionSheet常用方法整理
什么是操作表單?看圖:

一看圖就明白了,毋需多說(shuō)。
UIActionSheet* mySheet = [[UIActionSheet alloc]
initWithTitle:@"ActionChoose"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Destroy"
otherButtonTitles:@"OK", nil];
[mySheet showInView:self.view];
與UIAlertView類似,我們也是在委托方法里處理按下按鈕后的動(dòng)作。記得在所委托的類加上UIActionSheetDelegate。
- (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{
//
}
看到那個(gè)紅色的按鈕沒(méi)?那是ActionSheet支持的一種所謂的銷毀按鈕,對(duì)某戶的某個(gè)動(dòng)作起到警示作用,
比如永久性刪除一條消息或者日志。如果你指定了一個(gè)銷毀按鈕他就會(huì)以紅色高亮顯示:
mySheet.destructiveButtonIndex=1;
與導(dǎo)航欄類似,操作表單也支持三種風(fēng)格 :
UIActionSheetStyleDefault //默認(rèn)風(fēng)格:灰色背景上顯示白色文字
UIActionSheetStyleBlackTranslucent //透明黑色背景,白色文字
UIActionSheetStyleBlackOpaque //純黑背景,白色文字
用法用例:
mySheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
常用方法和屬性
顯示ActionSheet方法:
1.在一個(gè)視圖內(nèi)部顯示,可以用showInView
[mySheet showInView:self];
2.如果要將ActonSheet 與工具欄或者標(biāo)簽欄對(duì)齊,可以使用showFromToolBar或showFromTabBar
[mySheet showFromToolBar:toolbar];
[mySheet showFromTabBar:tabbar];
解除操作表單
用戶按下按鈕之后,Actionsheet就會(huì)消失——除非應(yīng)用程序有特殊原因,需要用戶按下做個(gè)按鈕。用dismiss方法可令表單消失:
[mySheet dismissWithClickButtonIndex:1 animated:YES];
@property(nonatomic,copy) NSString *title;
設(shè)置標(biāo)題
@property(nonatomic) UIActionSheetStyle actionSheetStyle;
添加一個(gè)按鈕,會(huì)返回按鈕的索引
- (NSInteger)addButtonWithTitle:(NSString *)title;
[/code]
獲取按鈕標(biāo)題
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
獲取按鈕數(shù)量
@property(nonatomic,readonly) NSInteger numberOfButtons;
設(shè)置取消按鈕的索引值
@property(nonatomic) NSInteger cancelButtonIndex;
設(shè)置特殊標(biāo)記
@property(nonatomic) NSInteger destructiveButtonIndex;
視圖當(dāng)前是否可見(jiàn)
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
下面是幾種彈出方式,會(huì)根據(jù)風(fēng)格不同展現(xiàn)不同的方式:
- (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;
UIActionSheet代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
點(diǎn)擊按鈕時(shí)觸發(fā)的方法
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet;
視圖將要彈出時(shí)觸發(fā)的方法
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet;
視圖已經(jīng)彈出式觸發(fā)的方法
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
點(diǎn)擊按鈕后,視圖將要收回時(shí)觸發(fā)的方法
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
點(diǎn)擊按鈕后,視圖已經(jīng)收回時(shí)觸發(fā)的方法
相關(guān)文章
iOS使用Target如何快速科學(xué)的區(qū)分開(kāi)發(fā)環(huán)境詳解
這篇文章主要給大家介紹了關(guān)于iOS使用Target如何快速科學(xué)的區(qū)分開(kāi)發(fā)環(huán)境的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
iOS開(kāi)發(fā)中Swift逃逸閉包知識(shí)
這篇文章主要介紹了iOS開(kāi)發(fā)中Swift逃逸閉包的相關(guān)知識(shí)點(diǎn)以及需要注意的地方,需要的朋友收藏下吧。2018-02-02
Objective-C的緩存框架EGOCache在iOS App開(kāi)發(fā)中的使用
這篇文章主要介紹了Objective-C的緩存框架EGOCache在iOS App開(kāi)發(fā)中的使用,重點(diǎn)講解了EGOCache對(duì)緩存過(guò)期時(shí)間的檢測(cè)及處理,需要的朋友可以參考下2016-05-05
iOS中UIAlertController設(shè)置自定義標(biāo)題與內(nèi)容的方法
UIAlertController是iOS8推出的新概念,取代了之前的 UIAlertView和UIActionSheet(雖然現(xiàn)在仍可以使用,但是會(huì)有警告)。下面這篇文章主要給大家介紹了關(guān)于iOS中UIAlertController如何設(shè)置自定義標(biāo)題與內(nèi)容的相關(guān)資料,需要的朋友可以參考下。2017-10-10
iOS 簡(jiǎn)約日歷控件EBCalendarView的實(shí)現(xiàn)代碼
本篇文章主要介紹了iOS 簡(jiǎn)約日歷控件EBCalendarView的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
iOS實(shí)現(xiàn)無(wú)限循環(huán)輪播圖效果
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)無(wú)限循環(huán)輪播圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
iOS 高德地圖仿微信發(fā)送實(shí)時(shí)位置
這篇文章主要介紹了iOS 高德地圖仿微信發(fā)送實(shí)時(shí)位置,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03

