码迷,mamicode.com
首页 > 其他好文 > 详细

UIKit 框架之UIAlertController

时间:2015-05-25 17:58:55      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

IOS8之后增加了UIAlertController类,它可以表示UIAlertView和UIActionSheet.它继承自UIViewController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    ViewController *vc=[[ViewController alloc]init];
    UINavigationController *nvc=[[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController=nvc;
    return YES;
}

 

//
//  ViewController.m
//  AlertVC
//
//  Created by City--Online on 15/5/25.
//  Copyright (c) 2015年 XQB. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(100, 100, 50, 50);
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.layer.borderWidth=2.0;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    
    
} 
-(void)btnClick:(id)sender
{
//    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
//    
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.text=@"name";
//        textField.clearsOnBeginEditing=YES;
//    }];
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.text=@"password";
//        textField.clearsOnBeginEditing=YES;
//    }];
    
    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *actionOk=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"确定");
    }];
    UIAlertAction *actionCancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"取消");
    }];
    [alert addAction:actionOk];
    [alert addAction:actionCancel];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 技术分享技术分享技术分享

 

UIKit 框架之UIAlertController

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4528085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!