//底部彈窗
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];//StyleActionSheet是底部彈窗
[alert addAction:[UIAlertAction actionWithTitle:@"第一個" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//點擊第一個之后所做的事情
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"第二個" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
}]];//Destructive狀態的標題是紅色 表示要做一些危險操作
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];//cancel狀態在UI提現上是跟上邊兩個狀態分開的
[self presentViewController:alert animated:YES completion:nil];
//中間彈窗
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"請輸入賬號" message:nil preferredStyle:UIAlertControllerStyleAlert];//StyleAlert是中間彈窗
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"請輸入賬號";//占位文字
}];//添加文本輸入框
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];//cancel狀態在UI提現上是跟上邊兩個狀態分開的
[alert addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//點擊第一個之后所做的事情
NSString *zhanghaoStr = [alert.textFields[0] text];//拿到第一個輸入框的文字
NSLog(@"---------%@",zhanghaoStr);
}]];
[self presentViewController:alert animated:YES completion:nil];
//******通過利用kvc對字體顏色進行修改 *******//
UIAlertAction *alertAct = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alertAct setValue:[UIColor grayColor] forKey:@"_titleTextColor"];