//
// ViewController.swift
// UIAlertView2
//
// Created by liaojianguo on 15/11/15.
// Copyright © 2015年 liaojianguo. All rights reserved.
//
import UIKit
class 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.
}
}