一周的學習即將結(jié)束,今天學習到了霓虹燈的做法靠瞎,感覺很happy,分享一下制作方法
//應運程序代理類
//AppDelegate中的方法都是UIApplicationDelegate中的協(xié)議方法
//UIApplication應運程序類
class AppDelegate: UIResponder, UIApplicationDelegate {
//應用程序窗口闯捎,是AppDelegate類的屬性
var window: UIWindow?
//應運程序加載完成的時候觸發(fā)這個方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//想再window對象添加內(nèi)容妖碉,就在這個方法中實現(xiàn)
//UIScreen屏幕類
//UIScreen.main獲取屏幕對象
//UIScreen.main.bounds獲取屏幕大小
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
//讓window成為應用程序的主窗口,并使其可見
self.window?.makeKeyAndVisible()
//給window設置根視圖控制器
self.window?.rootViewController = UIViewController()
let redView = UIView(frame:CGRect(x: 107, y: 268, width: 200, height: 200))
redView.backgroundColor = #colorLiteral(red: 0.8537434687, green: 0.7977634797, blue: 0.9764705896, alpha: 1)
redView.tag = 200
self.window?.addSubview(redView)
redView.layer.cornerRadius = 100
let yellowView = UIView(frame:CGRect(x: 132, y: 293, width: 150, height: 150))
yellowView.backgroundColor = #colorLiteral(red: 0.8976129821, green: 0.6902934195, blue: 0.9686274529, 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.8227517346, green: 0.5248843816, blue: 0.9098039269, alpha: 1)
blueView.tag = 202
self.window?.addSubview(blueView)
blueView.layer.cornerRadius = 50
//參數(shù)1:定時執(zhí)行的間隔
//參數(shù)2:目標對象
//參數(shù)3:目標對象選擇執(zhí)行的方法
//參數(shù)4:用戶信息 nil
//參數(shù)5:定時器是否重復執(zhí)行
Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(changeColor), userInfo: nil, repeats: true)
return true
}
//MAPK:一定時器的目標對象執(zhí)行方法
func changeColor()? {
//print("定時器方法")
let redView = self.window?.viewWithTag(200)
//存儲redView背景顏色
let color = redView?.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 = color
}