zoukankan      html  css  js  c++  java
  • OC与Swift写AlertController

        在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);
        }
  • 相关阅读:
    【微信开发】【Asp.net MVC】-- 微信分享功能
    利用JS-SDK微信分享接口调用(后端.NET)
    C# ThreadPool类(线程池)
    C#多线程--线程池(ThreadPool)
    MongoDB允许其它IP地址访问
    解决ASP.Net第一次访问慢的处理(IIS8)
    GitLab版本管理
    基于句子嵌入的无监督文本摘要(附代码实现)zt
    简约机器学习复习笔记/速查手册(缺点是2018年1月的旧了)
    CRF学习的文章
  • 原文地址:https://www.cnblogs.com/xclidongbo/p/4117747.html
Copyright © 2011-2022 走看看