显示登录警报
以下代码适用于 iOS 8 及更低版本,用于创建登录警报。
// 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 = "user@stackoverflow.com";
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();