现在弹出框主要有四种需求:1.提示消息 2.要求输入密码 3.要求输入账号和密码 4.其他自定义界面
嘛,其他自定义界面的话必然是需要自定义了,那么前三种常见风格,到底要不要自定义呢
首先,新手,最直接想到的可能是,我自定义个view吧,需要的时候自己写个炫酷刁炸天的show动画就add上去了。熟练者可能想到的是,我继承吧,然后再重写父类方法吧。
不过,呢,自从iOS5后,苹果内置了123这三种风格的style,直接设置alert.alertViewStyle即可。世界一下子就简单起来。
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput, //密码输入方式,输入新字符后,旧字符自动变成黑点
UIAlertViewStylePlainTextInput, //普通输入框
UIAlertViewStyleLoginAndPasswordInput//同时出现普通输入框和密码输入框
};
初始化是这样子:
self.alert = [[UIAlertView alloc]initWithTitle:@"确认支付" message:@"请填写支付密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
self.alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[self.alert show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self.alert dismissWithClickedButtonIndex:0 animated:YES];
}else{
//得到输入框
UITextField *tf = [alertView textFieldAtIndex:0];
DLog(@"密码是%@",tf.text);
}
}
又简洁又美丽有木有!