如何用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"];