首页 > 移动平台 > 详细

iOS开篇——UI之UIActionSheet

时间:2015-11-24 06:12:45      阅读:416      评论:0      收藏:0      [点我收藏+]

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];

 

iOS开篇——UI之UIActionSheet

原文:http://www.cnblogs.com/gwkiOS/p/4990206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!