一,效果圖。 二,代碼。 RootViewController.h RootViewController.m ...
一,效果圖。
二,代碼。
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
<UIActionSheetDelegate>
@end
RootViewController.m
//點擊任何處,彈出UIActionSheet
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"標題" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
// 逐個添加按鈕(比如可以是數組迴圈)
[sheet addButtonWithTitle:@"Item A"];
[sheet addButtonWithTitle:@"Item B"];
[sheet addButtonWithTitle:@"Item C"];
// 同時添加一個取消按鈕
[sheet addButtonWithTitle:@"Cancel"];
sheet.cancelButtonIndex = sheet.numberOfButtons-1;
[sheet showInView:self.view];
}