import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 创建3个视图对象,其中第二个视图是第三个视图的父视图
let view1 = UIView(frame: CGRect(x: 20, y: 80, width: 200, height: 200))
view1.backgroundColor = UIColor.red
self.view.addSubview(view1)
let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
view2.bounds = CGRect(x: -40, y: -40, width: 200, height: 200)
view2.backgroundColor = UIColor.yellow
self.view.addSubview(view2)
let viewSub = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
viewSub.backgroundColor = UIColor.blue
view2.addSubview(viewSub)
}
}