Swift中UIKit的使用

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// Override point for customization after application launch.

self.window = UIWindow(frame: UIScreen.main.bounds)

self.window?.backgroundColor = #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)

self.window?.makeKeyAndVisible()

self.window?.rootViewController = UIViewController()

/*

//(UIView Layout) 视图布局

//frame bounds center

//frame决定的是一个视图,在他父视图的位置

let redView = UIView(frame: CGRect(x: 10, y: 20, width: 100, height: 150))

redView.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)

self.window?.addSubview(redView)

redView.frame.origin = CGPoint(x: 100, y: 200)

redView.frame.size = CGSize(width: 200, height: 200)

// frame既能决定他在父视图的位置,也能控制他在父视图上的大小

print(UIScreen.main.bounds)

//bouds 视图自身的边界,bounds决定自身上子视图的位置bouds的origin点默认和视图本身坐标系的点是重合的

print(redView.bounds)

let greenView = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))

greenView.backgroundColor = UIColor.green

redView.addSubview(greenView)

//不修改bounds的size, 修改bounds的origin

redView.bounds.origin = CGPoint(x: 50, y: 50)

print("中心点:\(redView.center)")

//无论一个视图的bounds怎么改变,这个视图的中心点都不会改变

*/

//视图层级关系

let a = UIView(frame: CGRect(x: 157, y: 200, width: 100, height: 100))

a.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)

self.window?.addSubview(a)

let b = UIView(frame: CGRect(x: 107, y: 150, width: 200, height: 200))

b.backgroundColor = #colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)

self.window?.addSubview(b)

//最后添加在上层

//视图a放在最上层显示

//self.window?.bringSubview(toFront: a)

//视图b放在最下层

//self.window?.sendSubview(toBack: b)

//删除视图b

//b.removeFromSuperview()

print(self.window?.subviews)

//        self.window?.exchangeSubview(at: <#T##Int#>, withSubviewAt: <#T##Int#>)

return true

}

你可能感兴趣的:(Swift中UIKit的使用)