- (void)createButton{
UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(10, 70, 300, 40);
[button setTitle:@"分享" forState:UIControlStateNormal];
[button addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)share{
[self createActionSheet];
}
- (void)createActionSheet{
UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"新浪微博" otherButtonTitles:@"腾讯",@"朋友圈",@"QQ好友", nil];
//sheet加到屏幕上
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
//buttonIndex从上往下 从0开始 跟alertView不太一样
switch (buttonIndex) {
case 0:{
self.view.backgroundColor = [UIColor yellowColor];
NSLog(@"0");
}
break;
case 1:
NSLog(@"1");
break;
case 2:
NSLog(@"2");
break;
case 3:
NSLog(@"3");
break;
case 4:
NSLog(@"4");
break;
default:
NSLog(@"hehe");
break;
}
}
效果图