The following code is for iOS 8 and lower for creating a login alert.
// Create the UIAlertView
var loginAlertView = new UIAlertView(title, message, null, cancelTitle, okTitle);
// Setting the AlertViewStyle to UIAlertViewStyle.LoginAndPasswordInput
loginAlertView.AlertViewStyle = UIAlertViewStyle.LoginAndPasswordInput;
// Getting the fields Username and Password
var usernameTextField = loginAlertView.GetTextField(0);
var passwordTextField = loginAlertView.GetTextField(1);
// Setting a placeholder
usernameTextField.Placeholder = "[email protected]";
passwordTextField.Placeholder = "Password";
// Adding the button click handler.
loginAlertView.Clicked += (alertViewSender, buttonArguments) =>
{
// Check if cancel button is pressed
if (buttonArguments.ButtonIndex == loginAlertView.CancelButtonIndex)
{
// code
}
// In our case loginAlertView.FirstOtherButtonIndex is equal to the OK button
if (buttonArguments.ButtonIndex == loginAlertView.FirstOtherButtonIndex)
{
// code
}
};
// Show the login alert dialog
loginAlertView.Show();