今天学习了UI
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.8549019694, green: 0.250980407, blue: 0.4784313738, alpha: 1)
self.window?.makeKeyAndVisible()
self.window?.rootViewController = UIViewController()
let redview = UIView(frame: CGRect(x: 107, y: 268, width: 200, height: 200))
redview.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, 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.9568627477, green: 0.6588235497, blue: 0.5450980663, 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.3647058904, green: 0.06666667014, blue: 0.9686274529, alpha: 1)
blueview.tag = 202
self.window?.addSubview(blueview)
blueview.layer.cornerRadius = 50
//定时器
//参数一:定时执行的间隔
//参数二:目标对象
//参数三:目标对象选者执行的方法
//参数四:用户信息nil
//参数五:定时器是否重复执行
Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(changecolor), userInfo: nil, repeats: true)
return true
}
//MARK:定时器找的目标对象的执行方法
func changecolor(){
let redview = self.window?.viewWithTag(200)
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
}
网友评论