标签:
UIActionSheet在iOS8.3之后已不建议使用。 可以使用
UIAlertController+UIAlertControllerStyleActionSheet获得同样的效果
创建UIActionSheet
UIActionSheet * as = [[UIActionSheet alloc]initWithTitle:@"选择一个英雄" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"德玛" otherButtonTitles:@"琴女", nil];
//设置样式 as.actionSheetStyle = UIActionSheetStyleBlackOpaque;
实现协议方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 0: NSLog(@"这是第0个"); break; case 1: NSLog(@"这是第1个"); break; default: break; } }
使用UIAlertController+UIAlertControllerStyleActionSheet实现
UIAlertController * ac = [UIAlertController alertControllerWithTitle:@"选择一个英雄" message:@"没事" preferredStyle:UIAlertControllerStyleActionSheet]; [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"取消"); }]]; [ac addAction:[UIAlertAction actionWithTitle:@"德玛" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"德玛"); }]]; [self presentViewController:ac animated:YES completion:nil];
标签:
原文地址:http://www.cnblogs.com/gwkiOS/p/4990206.html