importUIKit
classViewController:UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//設置背景view的顏色
self.view.backgroundColor=UIColor.whiteColor()
//聲明第一個button,初始化大小
var addBn=UIButton(frame:CGRect(x:30, y:30, width:60, height:40))
//設置button的標題以及狀態
addBn.setTitle("添加", forState:UIControlState.Normal)
//設置button的標題顏色以及狀態
addBn.setTitleColor(UIColor.blueColor(), forState:UIControlState.Normal)
addBn.setTitleColor(UIColor.greenColor(), forState:UIControlState.Highlighted)
//設置button的標題字體以及大小
addBn.titleLabel?.font=UIFont(name:"Zapfino", size:15)
//為button添加一個點擊事件
addBn.addTarget(self, action:"addButton", forControlEvents:UIControlEvents.TouchUpInside)
//將button添加到view上
self.view.addSubview(addBn);
}
//按鈕點擊事件
func addButton(){
NSLog("addBn");
}
}