创建UIButton、UIImageView
let btn = UIButton()
btn.frame = CGRectMake(100, 100, 100, 100)
btn.backgroundColor = UIColor.redColor()
self.view.addSubview(btn)
let imageView = UIImageView()
imageView.image = UIImage(named: "image")
imageView.frame = CGRectMake(100, 200, 100, 100)
self.view.addSubview(imageView)
元组
//类似 结构体和数组 的结合
let point = (x:10,y:20)
point.x//设值point.x = 30
point.y//取值
point.0
point.1
print(point)//(10, 20)
let (x,y) = (10,20)
let point1 = (x,y)
print("point1 \(point1)")//(10, 20)
流程控制
for _ in 1...5{
//不需要用到变量i时,用下划线_进行忽略,避免不必要的浪费
print("111")
}
//0..<5 --- [0,5)
for i in 0..<5{
print(i)
}
let pointa = (10,-10)
switch pointa {
case let(x,y) where x==y:
print("x==y")
case let(x,y) where x == -y:
print("x==-y")
default:
print("不在这两条线上")
}
标签 out
out:
for _ in 1...2 {
for _ in 1...3 {
print("做俯卧撑")
//break //退出本循环
break out//退出到外面out循环
}
print("休息一次")
}