//
// ViewController.h
// UIAlertViewAndUIActionSheet
//
// Created by hehe on 15/9/21.
// Copyright (c) 2015年 wang.hehe. All rights reserved.
//
#import
@interface ViewController : UIViewController
@end
//
// ViewController.m
// UIAlertViewAndUIActionSheet
//
// Created by hehe on 15/9/21.
// Copyright (c) 2015年 wang.hehe. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self creatButton];
}
#pragma mark ----------------------创建一个button
- (void)creatButton
{
UIButton *alertButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 100, 60, 30)];
[self.view addSubview:alertButton];
alertButton.backgroundColor = [UIColor grayColor];
[alertButton setTitle:@"弹出警告框" forState:UIControlStateNormal];
[alertButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
alertButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[alertButton addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside];
//*******************************************
UIButton *actionBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200, 200, 30)];
[self.view addSubview:actionBtn];
actionBtn.backgroundColor = [UIColor grayColor];
[actionBtn setTitle:@"弹出表单" forState:UIControlStateNormal];
[actionBtn setTitleColor:[UIColor redColor] forState:0];
actionBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
[actionBtn addTarget:self action:@selector(showActionSheet) forControlEvents:UIControlEventTouchUpInside];
}
- (void)showActionSheet
{
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"你确定要删除?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:@"确定", nil];
[as showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"10");
//当button 押下的时候调用
NSLog(@"index = %ld",buttonIndex);
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
NSLog(@"11");
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"12");
}
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"13");
}//
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"14");
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"15");
}
- (void)showAlert
{
//[注]不需要添加到父视图,不需要设定坐标
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"警告" message:@"输入的密码错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", @"ok",nil];
[av show];
av.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
av.tag =10;
}
#pragma mark ------------------------alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//当button 押下的时候调用
NSLog(@"index = %ld",buttonIndex);
}
- (void)willPresentAlertView:(UIAlertView *)alertView
{
NSLog(@"will present");
}
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
UITextField *tf = [alertView textFieldAtIndex:0];
if([tf.text isEqualToString:@"123"])
return YES;
else
return NO;
}
- (void)didPresentAlertView:(UIAlertView *)alertView
{
NSLog(@"0");
}
// after animation
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"1");
}
// before animation and hiding view
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"2");
}
// after animation
@end