一、iOS9.0以前
-(void)alertViewBeforeiOS9{
// UIAlertView 9.0以前
//1.創(chuàng)建UIAlertView對(duì)象
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"test" message:@"請(qǐng)輸入用戶(hù)名&密碼" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
//2.設(shè)置樣式
/*
UIAlertViewStyleDefault 默認(rèn),沒(méi)有輸入框
UIAlertViewStyleSecureTextInput, 密碼輸入框
UIAlertViewStylePlainTextInput 普通輸入框
UIAlertViewStyleLoginAndPasswordInput 普通輸入框 + 密碼輸入框
*/
alertView.alertViewStyle = UIAlertViewStyleDefault;
//3.顯示
[alertView show];
}
//UIAlertView回調(diào)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex{
NSLog(@"%zd",buttonIndex);
}
二、iOS9.0以后
-(void)alertViewAfteriOS9{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"test" message:@"請(qǐng)輸入用戶(hù)名&密碼" preferredStyle:UIAlertControllerStyleAlert];
//添加普通輸入框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {}];
//添加密碼輸入框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.secureTextEntry = YES;
}];
//添加取消按鈕 UIAlertActionStyleCancel - 文字是藍(lán)色的 只能使用一次
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}]];
//添加確定按鈕 UIAlertActionStyleDefault - 文字是藍(lán)色的 可以添加多個(gè)
[alert addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}]];
//添加確定按鈕 UIAlertActionStyleDestructive - 文字是紅色的 可以添加多個(gè)
[alert addAction:[UIAlertAction actionWithTitle:@"不管" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}]];
[self presentViewController:alert animated:YES completion:nil];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。