语法:
//1、@UIApplicationMain就是程序的入口 //2、只有.swift 没有.h/.m 在swift中默认全局共享 //3、所有的代码都包装在{},默认方法都有一个缩进
代码展示:
class ViewController:
UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let v =
UIView(frame:
CGRect(x:
0, y:
20, width:
100, height:
100))
v
.backgroundColor =
UIColor.red
view
.addSubview(v)
self.view.addSubview(v)
let btn =
UIButton(type:
.contactAdd)
v
.addSubview(btn)
btn
.addTarget(
self, action:
#selector(clickMe), for: .touchUpInside)
}
func clickMe(btn:
UIButton) -> () {
print(
#function)
print(
"按钮点击了")
print(btn)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
代码作用详解: ====》快速的标记代码,方便以后进行更改或者跳转到这里