如何用UIAlertController實(shí)現(xiàn)底部彈出選擇菜單的效果?廢話不多說腿宰,直接上代碼
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];
還可以改變按鈕的顏色
//設(shè)置`確定`按鈕的顏色
[sureBtn setValue:HEXCOLOR(0xff3e3e) forKey:@"titleTextColor"];
[cancelBtn setValue:HEXCOLOR(0x333333) forKey:@"titleTextColor"];