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);
}