提示框應(yīng)用UIAlertController

準(zhǔn)備工作(以下代碼不用寫)

typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
   UIAlertControllerStyleActionSheet = 0,// 從底部彈出
   UIAlertControllerStyleAlert// 從中心彈出
} NS_ENUM_AVAILABLE_IOS(8_0);

typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
   UIAlertActionStyleDefault = 0,
   UIAlertActionStyleCancel,
   UIAlertActionStyleDestructive
} NS_ENUM_AVAILABLE_IOS(8_0);

上干貨

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"文本對話框" message:@"登錄和密碼對話框" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    // 停止監(jiān)聽文本改變通知
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextFieldTextDidChangeNotification object:alertController.textFields.lastObject];
    // 打印第一個文本框的內(nèi)容
    NSLog(@"%@",alertController.textFields.firstObject.text);
    
}];
[alertController addAction:OKAction];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];

 UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:destructiveAction];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
    textField.backgroundColor = [UIColor redColor];
    textField.placeholder = @"請輸用戶名";   
}];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
    textField.backgroundColor = [UIColor redColor];
    textField.placeholder = @"請輸入密碼";
    textField.secureTextEntry = YES;// 以圓點格式顯示
    // 設(shè)置監(jiān)聽
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handleTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];
    
}];

// 將OK按鈕禁用
OKAction.enabled = NO;
self.alertAction = OKAction;//存儲OK按鈕

[self presentViewController:alertController animated:YES completion:nil];

從底部彈出提示框

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"OK/取消" message:@"請你登陸!" preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *OKaction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];

UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:nil];

[alertController addAction:OKaction];
[alertController addAction:cancleAction];
[alertController addAction:destructiveAction];

[self presentViewController:alertController animated:YES completion:nil];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,234評論 25 708
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,445評論 4 61
  • 老實說李安的電影真的很細膩。老套的劇情,甚至有點過于簡單,都被拍出花了。 比利和他的兄弟們站在舞臺上的時候,眼前是...
    南滄閱讀 447評論 0 0
  • 周六的夜晚 暖光的臺燈 許嵩的老歌 趴在枕頭上看書 人人都是產(chǎn)品經(jīng)理 親愛的人在旁邊擺弄魚鉤線 偶爾一句交談 真愛...
    lulululun閱讀 165評論 0 2

友情鏈接更多精彩內(nèi)容