ios 底部弹出选择菜单:UIAlertController使用

如何用UIAlertController实现底部弹出选择菜单的效果?废话不多说,直接上代码

UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    //添加确定
UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"退出登录" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull   action) {
        NSLog(@"确定");
       
        
  }];
 //将action添加到控制器
[alertVc addAction:cancelBtn];
[alertVc addAction :sureBtn];
    //展示
[self presentViewController:alertVc animated:YES completion:nil];

还可以改变按钮的颜色

//设置`确定`按钮的颜色
    [sureBtn setValue:HEXCOLOR(0xff3e3e) forKey:@"titleTextColor"];
    [cancelBtn setValue:HEXCOLOR(0x333333) forKey:@"titleTextColor"];

查看更多!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容