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.
}
}
// 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.
}
}
相关文章推荐
- iOS开发的22个诡异技巧,你知道多少?
- IOS小型计算器实例代码3 可实现连续计算
- IOS小型计算器实例代码2
- IOS小型计算器实例代码
- iOS多线程编程技术之NSThread、Cocoa NSOperation、GCD
- 黑马IOS学习笔记 - from day323
- 解除Xib文件中控件与变量的绑定
- 【小白装系统】——常见问题解决
- iOS查看类的私有方法
- iOS 新浪微博-5.3 首页微博列表_集成图片浏览器
- iOS 多线程编程技术--NSThread、Cocoa NSOperation、GCD
- iOS Crash: symbolicatecrash 工具
- iOS环形控制器、环形按钮
- iOS 中的 promise 模式
- iOS 简单弹幕效果
- IOS 自适应布局效果(附代码)
- 浅谈iOS设计模式之单例模式
- ios @property
- iOS开发之简单加法计算器
- 欢迎使用CSDN-markdown编辑器