UIAlertView_帶文本輸入框的提示框

這裏寫圖片描述

UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 20, 60, 40);
    btn.backgroundColor = [UIColor grayColor];
    [btn setTitle:@"按鈕" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

    UIAlertView* alertView = [[UIAlertView alloc]initWithTitle:@"溫馨提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
    alertView.tag = 1;
    //設置提示框的類型
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [self.view addSubview:alertView];

調用的方法:

-(void)btnAction:(UIButton*)sender
{
    UIAlertView* alertView = [self.view viewWithTag:1];
    [alertView show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //通過索引值找到賬號文本輸入框
    if (buttonIndex == 1) {
        UITextField* textField = [alertView textFieldAtIndex:0];
        //通過索引值找到密碼文本輸入框
        UITextField* textField1 = [alertView textFieldAtIndex:1];

        NSLog(@"賬號:%@ 密碼:%@",textField.text,textField1.text);
    }
發佈了48 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章