警告框小知识

来源:互联网 发布:蜘蛛源码 编辑:程序博客网 时间:2024/05/16 14:54
#import <UIKit/UIKit.h>@interface ViewController : UIViewController <UIAlertViewDelegate,UIActionSheetDelegate>#pragma mark 警告框遵守的协议 #pragma mark 提示框遵守的协议- (IBAction)creatAlertViewOne:(UIButton *)sender;- (IBAction)creatAlertViewTwo:(UIButton *)sender;- (IBAction)creatAlertViewThree:(UIButton *)sender;@end
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}- (IBAction)creatAlertViewOne:(UIButton *)sender {    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"警告框" message:@"信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];    [alert1 show];    alert1.tag = 11 ;}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if (alertView.tag == 11) {        if (buttonIndex == 0) {            NSLog(@"点击了取消按钮");        }else{            NSLog(@"点击了确定按钮");        }    }else if (alertView.tag == 22){                //获取警告框里面当前位置的输入框的信息//       NSString *str =  [alertView textFieldAtIndex:0 ].text;                NSLog(@"%i",buttonIndex);        switch (buttonIndex) {            case 0:                self.view.backgroundColor = [UIColor whiteColor];                break;            case 1:                self.view.backgroundColor = [UIColor redColor];                break;            case 2:                self.view.backgroundColor = [UIColor yellowColor];                break;            case 3:                self.view.backgroundColor = [UIColor greenColor];                break;            default:                break;        }    }}- (IBAction)creatAlertViewTwo:(UIButton *)sender {    UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"彩色" message:@"设置背景颜色" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"红色",@"横色",@"绿色", nil];    alert2.tag = 22 ;    alert2.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput ;    [alert2 show];}- (IBAction)creatAlertViewThree:(UIButton *)sender {            UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"颜色" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"定时砸蛋" otherButtonTitles:@"黑色",@"黄色",@"绿色",nil];            [sheet showInView:self.view];    //Toolbar工具条显示,点击空白位置可以将提示框消除 //    [sheet showFromToolbar:Toolbar];    }-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{//    NSLog(@"%i",buttonIndex);    //取消按钮现在在数组的最后一个位置,Title按钮在第一个位置    switch (buttonIndex) {        case 0:{            [self.view setBackgroundColor:[UIColor redColor]];            break;        }        case 1:{            [self.view setBackgroundColor:[UIColor blackColor]];            break;        }        case 2:{            [self.view setBackgroundColor:[UIColor yellowColor]];            break;        }        case 3:{            [self.view setBackgroundColor:[UIColor greenColor]];            break;        }        case 4:{                        [self.view setBackgroundColor:[UIColor whiteColor]];            break;        }        default:            break;    }}@end


0 0