[TwistedFate]UIAlertView

来源:互联网 发布:java入门代码例子 编辑:程序博客网 时间:2024/06/08 10:27

AlertView

初始化

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定删除?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

添加button

[alert addButtonWithTitle:@"注册"];

修改标题

alert.title = @"通知";

在弹窗中添加TextField

[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];    UITextField *text1 = [alert textFieldAtIndex:0];    UITextField *text2 = [alert textFieldAtIndex:1];    text1.keyboardType = UIKeyboardTypeNamePhonePad;    text2.keyboardType = UIKeyboardTypeURL;

显现 弹窗alert

[alert show];

弹窗多与button连用

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    button.frame = CGRectMake(100, 100, 100, 50);    button.backgroundColor = [UIColor redColor];    [button setTitle:@"打开" forState:UIControlStateNormal];    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];    [self.window addSubview:button];
- (IBAction)buttonPressed:(UIButton *)button{    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定删除?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];    //[alert addButtonWithTitle:@"注册"];     alert.title = @"hah ";    //alert.delegate = self;    [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];    UITextField *text1 = [alert textFieldAtIndex:0];    UITextField *text2 = [alert textFieldAtIndex:1];    text1.keyboardType = UIKeyboardTypeNamePhonePad;    text2.keyboardType = UIKeyboardTypeURL;    [alert show];   // [self.window addSubview:alert];    [alert release];   // NSLog(@"%d",alert.visible);}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"%ld",buttonIndex);}
0 0