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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,572评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 初识iOS APP开发#### 在iOS APP开发中, main函数仍是程序的入口和出口, 但main函数不需要...
    DeanYan阅读 6,330评论 0 3
  • VLC的集成和使用 VLC介绍 VLC Media Player (VideoLAN) 为 Windows、Lin...
    Pocket阅读 19,914评论 75 66
  • iOS_autoLayout_Masonry 概述 Masonry是一个轻量级的布局框架与更好的包装AutoLay...
    指尖的跳动阅读 1,195评论 1 4