您的位置:首页 > 产品设计 > UI/UE

UIAlertAction 和UIAlertController (UIAlertViewUIActionSheet)

2015-09-22 08:03 567 查看
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
    // Override point for customization after application launch.
//    self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
//    self.window.backgroundColor=[UIColor whiteColor];
//创建两个按钮
//    UIButton *but1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 50, 150, 30)];
//    [but1 setTitle:@"警报" forState:UIControlStateNormal];
//    but1.backgroundColor=[UIColor blackColor];
//    
//    [but1 addTarget:self action:@selector(actal:) forControlEvents:UIControlEventTouchUpInside];
//    UIButton *but2 = [[UIButton alloc]initWithFrame:CGRectMake(170, 50, 150, 30)];
//    [but2 setTitle:@"操作表" forState:UIControlStateNormal];
//    but2.backgroundColor=[UIColor blackColor];
//    [but2 addTarget:self action:@selector(actlist:) forControlEvents:UIControlEventTouchUpInside];
//
//    [self.window addSubview:but1];
//    [self.window addSubview:but2];
//    [self.window makeKeyAndVisible];
   return
YES;
}

//UIAlertView

//-(void)actal:(UIButton *)sender
//{
//    UIAlertView * alv = [[UIAlertView alloc]initWithTitle:@"标题" message:@"消息" delegate:self cancelButtonTitle:@"取消"
otherButtonTitles:@"其他", nil];
//    [alv show];
//}

//UIActionSheet
//-(void)actlist:(UIButton *)sender
//{
//    UIActionSheet *she = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destru" otherButtonTitles:@"other", nil];
//    [she showInView:self.window];
//}

在ios8中

- (void)viewDidLoad {
    [super
viewDidLoad];
    
  
    UIButton *but3 = [[UIButton
alloc]initWithFrame:CGRectMake(170,
250, 150,
30)];
    [but3 setTitle:@"表"
forState:UIControlStateNormal];
    but3.backgroundColor=[UIColor
blackColor];
    [but3 addTarget:self
action:@selector(actllist:)
forControlEvents:UIControlEventTouchUpInside];
    //在viewcontroller视图下
    [self.view
addSubview:but3];
    
}

-(void)actllist:(UIButton *)sender
{
    // UIAlertController UIAlertAction
    UIAlertController * alt =[UIAlertController
alertControllerWithTitle:@"title"
message:@"mes"
preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction * cancelbuttion = [UIAlertAction
actionWithTitle:@"got it"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
        NSLog(@"cancel hhh");
    }];

//alt add cancelvuttion
    [alt addAction:cancelbuttion];

    [self
presentViewController:alt
animated:NO
completion:nil];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: