import UIKit
class NextViewController: UIViewController {
var label = UILabel()
var labelContent = " "
var button = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
//创建一个按钮,尺寸,标题,背景色,目标方法
button.frame = CGRectMake(20, 80, 50, 50)
button.setTitle("Back", forState: UIControlState.Normal)
button.backgroundColor = UIColor.blackColor()
button.addTarget(self, action: "backPressed:", forControlEvents: UIControlEvents.TouchUpInside) //TouchUpInside指离开按钮触发动作;TouchDown指按下触发,不管是否离开。
self.view.addSubview(button)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func backPressed(sender: AnyObject){
//返回上一个视图
dismissViewControllerAnimated(true, completion: nil) //撤回之前的视图的方法
}
网友评论