Snail—UI学习之弹出按钮选择项UIActionSheet

来源:互联网 发布:云端软件 知乎 编辑:程序博客网 时间:2024/05/21 09:04
- (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;    }        }


效果图



0 0
原创粉丝点击