Swift創(chuàng)建一個(gè)簡(jiǎn)易的霓虹燈

做一個(gè)簡(jiǎn)易的霓虹燈??

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

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

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

self.window?.makeKeyAndVisible()

self.window?.rootViewController = UIViewController()

let purpleView = UIView(frame: CGRect(x: 107, y: 268, width: 200, height: 200))

purpleView.backgroundColor = #colorLiteral(red: 0.8340440217, green: 0.7282580734, blue: 0.9568627477, alpha: 1)

purpleView.tag = 200

self.window?.addSubview(purpleView)

purpleView.layer.cornerRadius = 100

let yellowView = UIView(frame: CGRect(x: 132, y: 293, width: 150, height: 150))

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

yellowView.tag = 201

self.window?.addSubview(yellowView)

yellowView.layer.cornerRadius = 75

let blueView = UIView(frame: CGRect(x: 157, y: 318, width: 100, height: 100))

blueView.backgroundColor = #colorLiteral(red: 0.789335954, green: 0.9700479067, blue: 1, alpha: 1)

blueView.tag = 202

self.window?.addSubview(blueView)

blueView.layer.cornerRadius = 50

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

greenView.backgroundColor = #colorLiteral(red: 0.8137462465, green: 0.9644399958, blue: 0.8310004237, alpha: 1)

greenView.tag = 203

self.window?.addSubview(greenView)

greenView.layer.cornerRadius = 25

//定時(shí)器? 1.定時(shí)執(zhí)行的間隔? 2.目標(biāo)對(duì)象? 3.目標(biāo)對(duì)象執(zhí)行的方法? 4.用戶信息 nil? 5.定時(shí)器是否重復(fù)執(zhí)行

Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(changColor), userInfo: nil, repeats: true)

return true

}

//mark:定時(shí)器找的目標(biāo)對(duì)象執(zhí)行方法

func changColor(){

let purpleView = self.window?.viewWithTag(200)

//存儲(chǔ)redview背景顏色

let color = purpleView?.backgroundColor

self.window?.viewWithTag(200)?.backgroundColor = self.window?.viewWithTag(201)?.backgroundColor

self.window?.viewWithTag(201)?.backgroundColor = self.window?.viewWithTag(202)?.backgroundColor

self.window?.viewWithTag(202)?.backgroundColor = self.window?.viewWithTag(203)?.backgroundColor

self.window?.viewWithTag(203)?.backgroundColor = color

}

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:.

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末扎狱,一起剝皮案震驚了整個(gè)濱河市啥酱,隨后出現(xiàn)的幾起案子匣砖,更是在濱河造成了極大的恐慌沾鳄,老刑警劉巖带膀,帶你破解...
    沈念sama閱讀 221,548評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件箱靴,死亡現(xiàn)場(chǎng)離奇詭異淳地,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)唤冈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,497評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)误趴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人务傲,你說(shuō)我怎么就攤上這事≡嫔辏” “怎么了售葡?”我有些...
    開(kāi)封第一講書(shū)人閱讀 167,990評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)忠藤。 經(jīng)常有香客問(wèn)我挟伙,道長(zhǎng),這世上最難降的妖魔是什么模孩? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,618評(píng)論 1 296
  • 正文 為了忘掉前任尖阔,我火速辦了婚禮,結(jié)果婚禮上榨咐,老公的妹妹穿的比我還像新娘介却。我一直安慰自己,他們只是感情好块茁,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,618評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布齿坷。 她就那樣靜靜地躺著,像睡著了一般数焊。 火紅的嫁衣襯著肌膚如雪永淌。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 52,246評(píng)論 1 308
  • 那天佩耳,我揣著相機(jī)與錄音遂蛀,去河邊找鬼。 笑死干厚,一個(gè)胖子當(dāng)著我的面吹牛李滴,可吹牛的內(nèi)容都是我干的螃宙。 我是一名探鬼主播,決...
    沈念sama閱讀 40,819評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼悬嗓,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼污呼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起包竹,我...
    開(kāi)封第一講書(shū)人閱讀 39,725評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤燕酷,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后周瞎,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體苗缩,經(jīng)...
    沈念sama閱讀 46,268評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,356評(píng)論 3 340
  • 正文 我和宋清朗相戀三年声诸,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了酱讶。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,488評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡彼乌,死狀恐怖泻肯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情慰照,我是刑警寧澤灶挟,帶...
    沈念sama閱讀 36,181評(píng)論 5 350
  • 正文 年R本政府宣布,位于F島的核電站毒租,受9級(jí)特大地震影響稚铣,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜墅垮,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,862評(píng)論 3 333
  • 文/蒙蒙 一惕医、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧算色,春花似錦抬伺、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,331評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至斥废,卻和暖如春椒楣,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背牡肉。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,445評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工捧灰, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,897評(píng)論 3 376
  • 正文 我出身青樓毛俏,卻偏偏與公主長(zhǎng)得像炭庙,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子煌寇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,500評(píng)論 2 359

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