标签:
#import "RootViewController.h"
@interface RootViewController ()<UIActionSheetDelegate>
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
button.layer.borderWidth = 2;
[button setTitle:@"showSheet" forState:(UIControlStateNormal)];
[button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
[self.view addSubview:button];
[button addTarget:self action:@selector(show) forControlEvents:(UIControlEventTouchUpInside)];
}
- (void)show {
//UIActionSheet , 继承于UIView .
//创建方法
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"提示" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destructiveButton" otherButtonTitles:@"1", @"2", @"3", nil];
actionSheet.title = @"名字";//这里的 title 就是 创建方法里面的initWithTitle
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;//设置样式
//按钮的index destructiveButton , 1 ,2, 3, cancel , 分别是0 1 2 3 4
/*//四种样式
UIActionSheetStyleDefault
UIActionSheetStyleAutomatic
UIActionSheetStyleBlackOpaque
UIActionSheetStyleBlackTranslucent
*/
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{//代理里面的方法, 点击了哪个按钮
if (0 == buttonIndex) {
NSLog(@"0");
} else if (1 == buttonIndex) {
NSLog(@"1");
} else if (2 == buttonIndex) {
NSLog(@"2");
} else if (3 == buttonIndex) {
NSLog(@"3");
} else {
NSLog(@"4");
}
}
@end
标签:
原文地址:http://www.cnblogs.com/hsxblog/p/4934988.html