您的位置:首页 > 移动开发 > IOS开发

IOS Toast

2015-11-15 18:06 537 查看
//
// 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.

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: