一些UIAlertController的用法以及字體顏色的修改


//底部彈窗

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM