码迷,mamicode.com
首页 > 编程语言 > 详细

OC与Swift写AlertController

时间:2014-11-24 00:52:02      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   os   for   on   

    在iOS8以后,alertView和actionSheet,被 alertController所替代.今天用OC和swift,分别写了alertController.给大家做个参考.共勉.
OC:
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(100, 100, 100, 40);
    btn.backgroundColor = [UIColor yellowColor];
    [btn addTarget:self action:@selector(aa) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];

}
- (void)aa
{
    NSLog(@"%f",[[[UIDevice currentDevice] systemVersion] floatValue]);
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"报警" message:@"这是IOS8以后的报警" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * alertAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        NSLog(@"11111");
    }];
    [alertController addAction:alertAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
?


Swift:
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let btn:UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton;
        btn.backgroundColor = UIColor.yellowColor();
        btn.frame = CGRectMake(100, 100, 100, 40);
        btn.addTarget(self, action: "aa", forControlEvents: UIControlEvents.TouchUpInside);
        self.view.addSubview(btn);
        
        
    }
?
    func aa(){
        var alertController:UIAlertController = UIAlertController(title: "报警", message: "ios和Swifit", preferredStyle: UIAlertControllerStyle.Alert);
        var alertAction:UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil);
        alertController.addAction(alertAction);
        self.presentViewController(alertController, animated: true, completion: nil);
    }

OC与Swift写AlertController

标签:des   style   blog   io   ar   color   os   for   on   

原文地址:http://www.cnblogs.com/xclidongbo/p/4117747.html

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