import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//设置window大小,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()
self.window?.rootViewController = UIViewController()
//
let Label = UILabel(frame: CGRect(x: 40, y: 40, width: 250, height: 20))
Label.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
self.window?.addSubview(Label)
Label.font = UIFont.systemFont(ofSize: 17.0)
Label.textColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
Label.textAlignment = .center
Label.tag = 200
//
let Textfield = UITextField(frame: CGRect(x: 40, y: 100, width: 250, height: 20))
Textfield.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
Textfield.borderStyle = .roundedRect
self.window?.addSubview(Textfield)
Textfield.placeholder = "请输入内容"
Textfield.keyboardType = .namePhonePad
Textfield.tag = 201
//
let button = UIButton(type: .custom)
button.frame = CGRect(x: 40, y: 140, width: 60, height: 50)
button.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
button.setTitle("上去", for: .normal)
button.setTitle("上去了", for: .highlighted)
self.window?.addSubview(button)
button.addTarget(self, action: #selector(button1), for: .touchUpInside)
let button2 = UIButton(type: .custom)
button2.frame = CGRect(x: 160, y: 140, width: 60, height: 50)
button2.setTitle("播放", for: .normal)
button2.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
self.window?.addSubview(button2)
button2.addTarget(self, action:#selector(playbutton), for: .touchUpInside)
return true
}
func button1(abutton:UIButton) {
let label = self.window?.viewWithTag(200)as! UILabel
let Textfield = self.window?.viewWithTag(201)as! UITextField
label.text = Textfield.text
}
func playbutton(abutton:UIButton) {
var i = 0
if i == 0{
abutton.setTitle("暂停", for: .normal)
i = 1
}else{
abutton.setTitle("播放", for: .normal)
i = 0
}
}
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:.
}
}
网友评论