IOS Toast

来源:互联网 发布:有所不行 知和而和 编辑:程序博客网 时间:2024/05/21 09:11



////  ViewController.swift//  UIAlertView2////  Created by liaojianguo on 15/11/15.//  Copyright © 2015年 liaojianguo. All rights reserved.//import UIKitclass ViewController: UIViewController {         var alertView:UIAlertView?            func createUIButton()->UIButton{                                let button:UIButton = UIButton()                let frame = CGRectMake(100,60,100, 60)                button.setTitleColor(UIColor.redColor(), forState:UIControlState.Normal)                button.frame = frame                button.setTitle("点我有惊喜", forState:UIControlState.Normal)                button.addTarget(self, action:"onClick", forControlEvents:UIControlEvents.TouchUpInside)                return button                            }                func onClick(){                createUIAlertView()                            }                func createUIAlertView(){                                alertView = UIAlertView()                alertView!.title = "提示"                alertView!.message = "你好,我是007"                alertView!.addButtonWithTitle("点击我")                NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector:"dismiss:", userInfo:alertView!, repeats:false)                alertView!.show()                            }                func dismiss(timer:NSTimer){                alertView!.dismissWithClickedButtonIndex(0, animated:true)            }        override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.                                self.view.addSubview(createUIButton())    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.                    }}


0 0
原创粉丝点击