UISwift布局

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

//UIScreen.main.bounds獲取當前設備屏幕大小

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

self.window?.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1)

//使window成為成為應用程序主窗口并使其可見

self.window?.makeKeyAndVisible()

//給window設置根視圖控制器(現(xiàn)在只做了解)

self.window?.rootViewController = UIViewController()

/*

//UIView layout 視圖布局

//frame bounds center

//frame決定的是一個視圖庸诱,在他父視圖的位置

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

redView.backgroundColor = #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)

self.window?.addSubview(redView)

//frame技能決定它在父視圖的位置孕似,也能控制它在父視圖上的大小

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

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

//輸出當前屏幕的大小

print(UIScreen.main.bounds)

//bounds 視圖自身的邊界,bounds決定自身上子視圖的位置 以redview為坐標母截,bounds的origin點默認和視圖本身的坐標系的原點是重合的

print(redView.bounds)

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

greenView.backgroundColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)

redView.addSubview(greenView)

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

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

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

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

print(greenView.frame)

//無論視圖的bounds怎么改變脂矫,這個視圖的中心點都不會改變

*/

//視圖的層級關系

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

a.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)

self.window?.addSubview(a)

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

b.backgroundColor = #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)

self.window?.addSubview(b)

//誰最后添加誰就在最上層

//1.將視圖a放在最上層顯示

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

//2.將視圖b放在最下層顯示

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

//3.刪除最后添加的視圖b

//b.removeFromSuperview()

//4.交換兩個視圖

//print(self.window?.subviews)

self.window?.exchangeSubview(at: 1, withSubviewAt: 2)

return true

}

func applicationWillResignActive(_ application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

func applicationDidEnterBackground(_ application: UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(_ application: UIApplication) {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(_ application: UIApplication) {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(_ application: UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

}

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末淌铐,一起剝皮案震驚了整個濱河市塞弊,隨后出現(xiàn)的幾起案子贸辈,更是在濱河造成了極大的恐慌,老刑警劉巖碰逸,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件乡小,死亡現(xiàn)場離奇詭異,居然都是意外死亡饵史,警方通過查閱死者的電腦和手機满钟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門胳喷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人吭露,你說我怎么就攤上這事〗哺停” “怎么了泥兰?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長题禀。 經(jīng)常有香客問我,道長迈嘹,這世上最難降的妖魔是什么削彬? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮江锨,結果婚禮上吃警,老公的妹妹穿的比我還像新娘啄育。我一直安慰自己酌心,他們只是感情好挑豌,可當我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布安券。 她就那樣靜靜地躺著,像睡著了一般侯勉。 火紅的嫁衣襯著肌膚如雪鹦筹。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天址貌,我揣著相機與錄音铐拐,去河邊找鬼。 笑死练对,一個胖子當著我的面吹牛遍蟋,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播螟凭,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼虚青,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了螺男?” 一聲冷哼從身側響起棒厘,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎下隧,沒想到半個月后奢人,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡淆院,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年达传,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片迫筑。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖宗弯,靈堂內(nèi)的尸體忽然破棺而出脯燃,到底是詐尸還是另有隱情,我是刑警寧澤蒙保,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布辕棚,位于F島的核電站,受9級特大地震影響邓厕,放射性物質(zhì)發(fā)生泄漏逝嚎。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一详恼、第九天 我趴在偏房一處隱蔽的房頂上張望补君。 院中可真熱鬧,春花似錦昧互、人聲如沸挽铁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽叽掘。三九已至楣铁,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間更扁,已是汗流浹背盖腕。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留浓镜,地道東北人溃列。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像竖哩,于是被迫代替她去往敵國和親哭廉。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內(nèi)容