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);
        }
  • 相关阅读:
    Visual Stdio VS 错误 error : 0xC00000FD: Stack overflow. 更改堆栈空间解决栈溢出问题
    OpenCV Mat 只能用静态数组定义时初始化,动态数组赋值给Mat需要逐元素进行. MATLAB,OpenCV,VS混合编程
    【转】Ubuntu 10.10升级显卡驱动后开机动画低分辨率问题
    linux 文件[名]编码
    L337 Speak及国外论坛、IRC常用缩写
    UCS2 手机SMS的PDU编码
    setuid
    【转】CentOS5.5硬盘安装
    SWT CTabFolder 简记
    [转] 程序员的十层楼
  • 原文地址:https://www.cnblogs.com/xclidongbo/p/4117747.html
Copyright © 2011-2022 走看看