1. Import and manage picture footage using a resource folder
/*
* The resource folder allows you to manage your pictures without the need to add a suffix to the image. It can also improve the security of the software, it will tell the picture is encrypted compression,
* and saved to the Assets.car file.
*/
Create an image class to load and draw the image.
Let img = UIImage (named: "Pic2.png")//Under Test (XCODE): Let img = UIImage (named: "Pic2")
Let Imgview = Uiimageview (image:img)
Self.view.addSubview (Imgview)
2. Application Life cycle
Func application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?)- > Bool {
Override point for customization after application launch.
The code that needs to be executed after loading the program, written in the method that the program completes loading, the common method
Print (">>>didfinishlaunchingwithoptions")
return True
}
Func applicationwillresignactive (application:uiapplication) {
Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state.
Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
Inactive, during which the program does not accept messages and events
Print (">>>applicationwillresignactive")
}
Func Applicationdidenterbackground (application:uiapplication) {
Use the This method to release the shared resources, save user data, invalidate timers, and store enough application state info Rmation to the restore your application to the it is terminated later.
If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits.
When the program is pushed to the background, call the secondary method, if you set the background to continue some actions, then add code in this method can be
Print (">>> applicationdidenterbackground")
}
Func Applicationwillenterforeground (application:uiapplication) {
Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the background.
Backstage, front desk
}
Func applicationdidbecomeactive (application:uiapplication) {
Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.
When you enter active state, this method is executed
}
Func applicationwillterminate (application:uiapplication) {
Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.
This method is called when the program is going to exit. Usually used to save data, and some cleanup work before exiting
}
3 quickly find and open files
1. Select the [Quick Open] submenu to quickly find project documents that will provide you with great convenience when you work on a large project.
2. Click the button on the keyboard to filter the document by typing in keywords
Shortcut keys: Command + Shift + O
4. Quickly change the variable with the same name
In the edit area of the code, click to locate the variable that needs to change the name
Open the menu bar, Edit menu, select Refactor This menu, select the Rename command, which allows you to uniformly modify a variable in the document. , enter a new name in the Name box
5. Find and Replace code
6. Basic use of views
Let Rect1 = CGRect (x:30, y:50, width:200, height:200)
Let View1 = UIView (Frame:rect1)
View1.backgroundcolor = Uicolor.browncolor ()
Let Rect2 = CGRect (x:90, y:120, width:200, height:200)
Let View2 = UIView (FRAME:RECT2)
View2.backgroundcolor = Uicolor.purplecolor ()
Self.view.addSubview (View1)
Self.view.addSubview (VIEW2)
7. Hierarchical relationship of views
Let View1 = UIView (Frame:cgrect (x:20, y:80, width:280, height:280))
View1.backgroundcolor = Uicolor.redcolor ()
Self.view.addSubview (View1)
Let View2 = UIView (Frame:cgrect (x:0, y:0, width:200, height:200))
Sets the position and size of the view's local coordinate system, which affects the location of the child view and the display
View2.bounds = CGRect (x: -40, y: -20, width:200, height:200)
View2.backgroundcolor = Uicolor.yellowcolor ()
Self.view.addSubview (VIEW2)
Let viewsub = UIView (Frame:cgrect (x:0, y:0, width:100, height:100))
Viewsub.backgroundcolor = Uicolor.bluecolor ()
View2.addsubview (Viewsub)
8. Basic operation of the view
Override Func Viewdidload () {
Super.viewdidload ()
Additional setup after loading the view, typically from a nib.
Adding and removing views, toggling the hierarchy of views in the parent view
Let rect = CGRect (x:30, y:50, width:200, height:200)
Let view = UIView (Frame:rect)
View.backgroundcolor = Uicolor.browncolor ()
Self.view.addSubview (view)
Let Btadd = UIButton (Frame:cgrect (x:30, y:350, width:80, height:30))
Btadd.backgroundcolor = Uicolor.graycolor ()
Btadd.settitle ("Add", Forstate:uicontrolstate ())
Btadd.addtarget (Self, Action: #selector (Viewcontroller.addview (_:)), forControlEvents: Uicontrolevents.touchupinside)
Self.view.addSubview (Btadd);
Let Btback = UIButton (Frame:cgrect (x:120, y:350, width:80, height:30))
Btback.backgroundcolor = Uicolor.graycolor ()
Btback.settitle ("Switch", Forstate:uicontrolstate ())
Btback.addtarget (Self, Action: #selector (Viewcontroller.bringviewback (_:)), forControlEvents: Uicontroleventtouchdragexit)
Self.view.addSubview (Btback);
Let Btremove = UIButton (Frame:cgrect (x:210, y:350, width:80, height:30))
Btremove.backgroundcolor = Uicolor.graycolor ()
Btremove.settitle ("Remove", Forstate:uicontrolstate ())
Btremove.addtarget (Self, Action: #selector (Viewcontroller.removeview (_:)), forControlEvents: Uicontroleventtouchdragexit)
Self.view.addSubview (Btremove);
}
Func AddView (_ Sender:uibutton)
{
Let rect = CGRect (x:60, y:90, width:200, height:200)
Let view = UIView (Frame:rect)
View.backgroundcolor = Uicolor.purplecolor ()
View.tag = 1;
Self.view.addSubview (view)
}
Func Bringviewback (_sender:uibutton)
{
Let view = Self.view.viewWithTag (1)
Self.view.sendSubviewToBack (view!)
}
Func Removefromview (_sender:uibutton)
{
Let view = Self.view.viewWithTag (1)
View?. Removefromsuperview ();
}
Ios-swift3 & XCode8