UI 1

import UIKit

@UIApplicationMain? //main函數(shù)

// 應(yīng)用程序代理類

//AppDelegate中的方法都是UIApplicationDelegate中的協(xié)議方法

//UIApplication? 應(yīng)用程序類

class AppDelegate: UIResponder, UIApplicationDelegate {

// 應(yīng)用程序窗口矾睦,是AppDelegate類色屬性

var window: UIWindow?

//應(yīng)用程序加載完成時(shí)觸發(fā)這個(gè)方法

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

// 想在window對(duì)象添加內(nèi)容盐须,就在這個(gè)方法中實(shí)現(xiàn)

//UIScreen 屏幕類

//UIScreen.main 獲取屏幕對(duì)象

//UIScreen.main.bounds 屏幕大小

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

//顏色

self.window?.backgroundColor = #colorLiteral(red: 1, green: 0.6225224255, blue: 0.6268012779, alpha: 1)

//讓window成為應(yīng)用程序的主窗口,并使其可見(jiàn)

self.window?.makeKeyAndVisible()

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

self.window?.rootViewController = UIViewController()

//(一般一個(gè)應(yīng)用程序只需要一個(gè)UIWindow對(duì)象)

/*

//UIView的創(chuàng)建方式(五個(gè)視圖)

let redView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

redView.backgroundColor = #colorLiteral(red: 1, green: 0.1491314173, blue: 0, alpha: 1)

//向window上添加一個(gè)子視圖

self.window?.addSubview(redView)

//獲取屏幕的寬

let screenWidth = UIScreen.main.bounds.size.width

//獲取屏幕的高

let screenHeight = UIScreen.main.bounds.size.height

let greenView = UIView(frame: CGRect(x: screenWidth - 100, y: 0, width:100 , height: 100))

greenView.backgroundColor = #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)

self.window?.addSubview(greenView)

let yellowView = UIView(frame: CGRect(x: 0, y: screenHeight - 100, width: 100, height: 100))

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

self.window?.addSubview(yellowView)

let perploView = UIView(frame: CGRect(x: screenWidth - 100, y: screenHeight - 100, width: 100, height: 100))

perploView.backgroundColor = #colorLiteral(red: 0.8549019694, green: 0.250980407, blue: 0.4784313738, alpha: 1)

self.window?.addSubview(perploView)

let yellow = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

//yellow中心點(diǎn)和window中心點(diǎn)重合

yellow.center = (self.window?.center)!

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

self.window?.addSubview(yellow)

*/

let centerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

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

self.window?.addSubview(centerView)

//UIView 的常用屬性

//alpha 透明度? 0.0~1.0

centerView.alpha = 1.0

//hidden 顯隱性 true是隱藏 false是顯示(默認(rèn)值)

centerView.isHidden = false

//superView 獲取到父視圖的屬性

let fatherView = centerView.superview

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

//向centerView上添加子視圖

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

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

//子視圖超出父視圖的邊界郊霎,就把超出部分剪掉了(了解)

//centerView.clipsToBounds = true

//tag值屬性 給一個(gè)視圖添加一個(gè)唯一標(biāo)識(shí)(0~100不要在使用了)

greenView.tag = 200

centerView.addSubview(greenView)

//subViews屬性簿透,獲取子視圖的屬性,返回值是一個(gè)數(shù)組移袍,

let arr = centerView.subviews

let newView = arr[0]

newView.backgroundColor = UIColor.blue

//根據(jù)tag值獲取視圖對(duì)象

let newView2 = centerView.viewWithTag(200)

newView2?.backgroundColor = UIColor.cyan

return true

}

//應(yīng)用程序?qū)⒁∠钴S狀態(tài)時(shí)觸發(fā)

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.

}

//已經(jīng)進(jìn)入后臺(tái)時(shí)觸發(fā)

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.

}

//將要進(jìn)入前臺(tái)時(shí)觸發(fā)

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.

}

//應(yīng)用程序已經(jīng)變的活躍時(shí)觸發(fā)

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.

}

//程序?qū)⒁Y(jié)束的時(shí)候觸發(fā)

func applicationWillTerminate(_ application: UIApplication) {

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

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末晾嘶,一起剝皮案震驚了整個(gè)濱河市奸笤,隨后出現(xiàn)的幾起案子圣絮,更是在濱河造成了極大的恐慌枝秤,老刑警劉巖宿亡,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異态蒂,居然都是意外死亡骡苞,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門喘先,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)钳吟,“玉大人,你說(shuō)我怎么就攤上這事窘拯『烨遥” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵涤姊,是天一觀的道長(zhǎng)暇番。 經(jīng)常有香客問(wèn)我,道長(zhǎng)思喊,這世上最難降的妖魔是什么壁酬? 我笑而不...
    開(kāi)封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮搔涝,結(jié)果婚禮上厨喂,老公的妹妹穿的比我還像新娘。我一直安慰自己庄呈,他們只是感情好蜕煌,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著诬留,像睡著了一般斜纪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上文兑,一...
    開(kāi)封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天盒刚,我揣著相機(jī)與錄音,去河邊找鬼绿贞。 笑死因块,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的籍铁。 我是一名探鬼主播涡上,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼拒名!你這毒婦竟也來(lái)了吩愧?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤增显,失蹤者是張志新(化名)和其女友劉穎雁佳,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡糖权,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年堵腹,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片星澳。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡秸滴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出募判,到底是詐尸還是另有隱情,我是刑警寧澤咒唆,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布届垫,位于F島的核電站,受9級(jí)特大地震影響全释,放射性物質(zhì)發(fā)生泄漏装处。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一浸船、第九天 我趴在偏房一處隱蔽的房頂上張望妄迁。 院中可真熱鬧,春花似錦李命、人聲如沸登淘。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)黔州。三九已至,卻和暖如春阔籽,著一層夾襖步出監(jiān)牢的瞬間流妻,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工笆制, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留绅这,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓在辆,卻偏偏與公主長(zhǎng)得像证薇,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子开缎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353

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