The last article mainly mentions some of the techniques and knowledge used in imitation Sina Weibo, so this article begins to enter the formal project implementation stage. The first thing to do is to create the project and the related settings, as well as the basic framework of the building.
I. Project creation and related settings
1. Project Creation
More and more companies are now using Swift to develop iOS and AppleWatch projects, so our development is also using the swift language to create new projects that are set up as follows:
Since it is imitation, nature can be regarded as an exercise, project name: "Weibotest", programming language Select "Swift". Then "next" until the creation is complete.
2. Apply icon Settings
Drag the app icon into the specified position (Images.xcassets-AppIcon, and point to the dashed square in the middle until the mouse pointer changes to a green plus sign to let go), and Xcode will automatically complete the settings according to the picture name, as follows:
Note: By default, due to Xcode's own cause, you can't see the two icons on the right that support iOS 7,8, only if you close the left or right panel of Xcode.
3. Splash screen Settings
Start screen settings relative to some trouble, here first about the start screen settings related to the development history.
The iphone 5, which comes with iOS 71, is starting to break through the 3.5-inch screen that the iphone has maintained for the past 4-inch era, to make it easy for developers to develop apps that are compatible with the iphone 4S's 3.5-inch screen and iphone 5 's 4-inch screen. Apple launched the launch image technology to fit two different screens in a single development. In this case, the developer can complete the setup only by providing different splash images depending on the screen size.
And in the era of iOS 8, with the iphone 6 and 6 Plus interviews, The iphone's screen size again adds 4.7-inch and 5.5-inch two sizes, and to better fit the screen, Apple has introduced a new screen-fitting technology: Launchscreen, which uses a constrained auto-fit approach to fit the screen, compared to iOS 7 launch Image can improve the development efficiency more. However, according to the current development situation in China, the company using launch image for development is still very much, Sina Weibo is also used this way.
Similarly, Apple's development approach to system compatibility is always forward-compatible generation, and even in the latest Xcode development tools, it is still supported for development using launch image. Therefore, in this development, we also use this approach to develop, the following steps:
Click Project, General, to enter the project Settings screen
Locate the "Launch screen File" below, remove the value, and enter, select "Migrate" in the Pop-up tab
After completing the above steps, you can find that images.xcassets a more than one of the options called Launchimage, click to see the following settings:
Is this setting interface very similar to the one that sets the app icon? Drag the picture directly into the app icon, and Xcode will automatically configure it, such as:
We found a warning in the upper right corner, prompted by two not set (Unassigned) of the picture, according to the name of the picture, we can see that this is actually support the iphone 6plus Retina 5.5-inch screen, vertical screen start picture, but the above is actually set up, You can therefore delete the settings for both pictures. After you delete the two pictures, you can see that the warning has disappeared.
At this point, the project creation and related settings have been completed.
Second, the basic framework construction
In the first installment, it was mentioned that the mainstream development framework was developed in the form of Tabbarcontroller + Navigationcontroller, which was also used in this development.
In order to reduce the complexity of the development, referring to the micro-BO interface after I simply designed the development of the basic construction method, the specific scheme is as follows:
To facilitate subsequent file management, I have also created the following file directories to manage the project files in a differentiated format, as follows:
Start creating files according to the design framework:
Where the Uitabbarcontroller is dragged into the master storyboard and set to initialize the boot controller:
In storyboard of other display sub-interfaces, drag into Uitableviewcontroller and embed Uinavigationcontroller, set Uinavigationcontroller to initialize the startup controller:
Finally, in each storyboard, a corresponding custom controller class is set to the corresponding controller:
Finally, you will need to drag into the images.xcassets, you need to manually set the content of the basic end, the following formally into the code phase.
1. Add a child view Controller
Since the Tableviewcontroller child View controller is distributed in different storyboard, the first thing to do is to add the child view controller in each storyboard to the Tabbarcontroller.
The specific code is as follows:
Import UIKitclassMaintabbarcontroller:uitabbarcontroller {Overridefunc viewdidload () {super.viewdidload () addchildviewcontrollers ()}/** Load all the child view controllers*/ Privatefunc addchildviewcontrollers () {Self.tabBar.tintColor=Uicolor.orangecolor () Addchildviewcontroller (storyboardname:"Homepage", Title:"Home Page", Iconname:"Tabbar_home") Addchildviewcontroller (storyboardname:"Message", Title:"message", Iconname:"Tabbar_message_center") Addchildviewcontroller (storyboardname:"Discover", Title:"found", Iconname:"Tabbar_discover") Addchildviewcontroller (storyboardname:" Profile", Title:"I'm", Iconname:"Tabbar_profile") } /** Load Child view Controller:p aram:storyboardname Storyboard name:p aram:title title:p aram:iconname Icon Name*/ Privatefunc Addchildviewcontroller (#storyboardName: String, title:string, iconname:string) {/** * Remove the initialization controller from the storyboard*/Let SB=Uistoryboard (Name:storyboardname, bundle:nil) Let Nav= Sb.instantiateinitialviewcontroller () as!Uinavigationcontroller/** * Set the relevant properties that the controller displays on Tabbar*/Nav.title=title Nav.tabBarItem.image=UIImage (named:iconname) nav.tabBarItem.selectedImage= UIImage (Named:iconname +"_highlighted") /** * Add the completed controller as a sub-controller to the Tabbarcontroller*/Addchildviewcontroller (NAV)}}
The results of the operation are as follows:
At this point, the basic framework of the construction work has been completed.
Zatan
1. Using storyboard/xib and using pure code development:
Storyboard/xib is developed graphically, and the relationship between UI controls is much clearer and straightforward. There are still a lot of companies still using the code-only way to develop the UI, in terms of the efficiency of development, the use of storyboard/xib is significantly higher than the pure Code development, and in the use of constraints and automatic layout more and more mainstream, the efficiency of the difference is more obvious. Pure code development only in the early days of iOS development had to choose the way, the time as money and life for the present, pure code development can be as a skill master, peacetime development should be more use of storyboard/xib to do.
2. Do you want to handle the warning?
Everyone likes code without errors and warnings, so that there is no problem with running the code at least. From a development perspective, a warning is only a potential error, but does not guarantee when the error will occur, so in order to ensure the absolute security of the code to run, every time a warning is generated, you should fix it as soon as possible, and if your warning accumulates to hundreds of thousands of times, It is estimated that the great God will not have the desire to deal with the warning!
Imitation Sina Weibo iOS Client II-Project foundation construction and related settings