Reprint please indicate source: http://blog.csdn.net/android_ls/article/details/45827719
Disclaimer: Sina Weibo project, the use of all the image resources are derived from the official Sina Weibo iOS client, the purpose of writing this application is to learn communication, such as infringement please inform, I will promptly replace the relevant pictures used.
Recently I intend to use my spare time, imitate the Sina Weibo iOS client, as to can write where I am not sure, can write how much to write, below we start the basic construction of the project:
1. Open Xcode Select Create New project, and create the directory structure of each module, complete the directory structure of the project such as:
2, I use the real folder to organize the code of each module, select the Classes folder, right-click the show in Finder can see the following several files:
Click on the Classes folder to enter, see the following several files:
Through the above steps, you can see, to organize each module code folder in the hard disk is real, the advantage is that the code of each module is clearly divided, a module needs to be modified or added function, directly find the corresponding module operation.
3, set the application icon in images.xcassets such as:
The corresponding configuration file (Contents.json) is as follows:
{"Images": [{"idiom": "iphone", "Size": "29x29", "scale": "1x"}, {"Size": "29x29", "Idiom": "iphone", "filename": "[email protected]", "scale": "2x"}, {"Size": "29x29" , "idiom": "iphone", "filename": "[email protected]", "scale": "3x"}, {"Size": "40x40 "," idiom ":" iphone "," filename ":" [email protected] "," scale ":" 2x "}, {" idiom ":" Iph One "," Size ":" 40x40 "," scale ":" 3x "}, {" Size ":" 57x57 "," idiom ":" iphone "," filename " ":" Icon.png "," scale ":" 1x "}, {" Size ":" 57x57 "," idiom ":" iphone "," filename ":" [EMAIL&N Bsp;protected] "," scale ":" 2x "}, {" Size ":" 60x60 "," idiom ":" iphone "," filename ":" [email& Nbsp;protected] "," scale ":" 2x "}, {" Size ":" 60x60 "," idiom ":" iphone "," filename ":" [email protected] ","Scale": "3x"}], "info": {"version": 1, "author": "Xcode"}}
4, set the picture of launchimage such as:
If you want your app to display correctly on 4S, 5, 5S, 6, and 6plus, there are a few images in the corresponding launchimage, each with the following dimensions:
Image size corresponding to Retina HD 5.5:1242?x?2208
Image size corresponding to Retina HD 4.7:750?x?1334
Image size for IPhone Portrait IOS 7,8 (Retina 4): 640?x?1136
IPhone Portrait IOS 7,8 (2x) corresponding image size: 640?x?960
For example, the Retina HD 4.7 is missing this picture, as follows: The left side of the launchimage is not added to the Retina HD 4.7, the right side is the normal situation of the display.
5, create UIWindow, set Rootviewcontroller and display the window, the specific code is as follows:
#pragma the first time the mark application finishes booting, the first call to the Proxy method-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions { //1, create UIWindow Self.window = [[UIWindow alloc] init]; Self.window.frame = [UIScreen mainscreen].bounds; 2. Set Rootviewcontroller self.window.rootViewController = [[Wbtabbarcontroller alloc] init]; 3. display window [Self.window makekeyandvisible]; return YES;}
6, create Wbtabbarcontroller class, let it inherit from Uitabbarcontroller; create Homeviewcontroller, Messageviewcontroller, Discoverviewcontroller and Profileviewcontroller let them all inherit from Uitableviewcontroller, in the wbtabbarcontroller.m file-(void) Add a concrete implementation to the Viewdidload {} function with the following code:
-(void) viewdidload { [super viewdidload]; _homeviewcontroller = [[Homeviewcontroller alloc]init]; [Self addchildcontroller:_homeviewcontroller title:@ "Home" image:@ "Tabbar_home"]; _messageviewcontroller = [[Messageviewcontroller alloc]init]; [Self addchildcontroller:_messageviewcontroller title:@ "message" image:@ "Tabbar_message_center"]; _discoverviewcontroller = [[Discoverviewcontroller alloc]init]; [Self addchildcontroller:_discoverviewcontroller title:@ "found" image:@ "Tabbar_discover"]; _profileviewcontroller = [[Profileviewcontroller alloc]init]; [Self Addchildcontroller:_profileviewcontroller title:@ "i" image:@ "Tabbar_profile"];}
In Images.xcassets, add the appropriate picture resources, add them as well as:
7, the Wbtabbarcontroller class complete code is as follows:
wbtabbarcontroller.m//sinaweibo////Created by Android_ls on 15/5/17.//Copyright (c) 2015 Android_ls. All rights reserved.////get RGB Color # define Kcolor (R, G, b) [Uicolor colorwithred: (r)/255.0 Green: (g)/255.0 Blue: (b)/255.0 al Pha:1] #import "WBTabBarController.h" #import "HomeViewController.h" #import "MessageViewController.h" #import " DiscoverViewController.h "#import" ProfileViewController.h "@interface Wbtabbarcontroller () {Homeviewcontroller * _ Homeviewcontroller; Messageviewcontroller * _messageviewcontroller; Discoverviewcontroller * _discoverviewcontroller; Profileviewcontroller * _profileviewcontroller;} @end @implementation wbtabbarcontroller-(void) viewdidload {[Super viewdidload]; _homeviewcontroller = [[Homeviewcontroller alloc]init]; [Self addchildcontroller:_homeviewcontroller title:@ "Home" image:@ "Tabbar_home"]; _messageviewcontroller = [[Messageviewcontroller alloc]init]; [Self addchildcontroller:_messageviewcontroller title:@ "message" image:@ "Tabbar_message_center"]; _discoverviewcontroller = [[Discoverviewcontroller alloc]init]; [Self addchildcontroller:_discoverviewcontroller title:@ "found" image:@ "Tabbar_discover"]; _profileviewcontroller = [[Profileviewcontroller alloc]init]; [Self Addchildcontroller:_profileviewcontroller title:@ "i" image:@ "Tabbar_profile"];} /** * Add sub-controller to Uitabbarcontroller */-(void) Addchildcontroller: (Uiviewcontroller *) Childviewcontroller title: ( NSString *) Title Image: (NSString *) image{//Set sub-controller, Tabbar and navigationbar title Childviewcontroller.title = title; Set the default indication picture on Tabbaritem and the picture when selected ChildViewController.tabBarItem.image = [UIImage imagenamed:image]; ChildViewController.tabBarItem.selectedImage = [[UIImage imagenamed:[nsstring stringwithformat:@ "%@%@", Image, @ "_ Selected "]]imagewithrenderingmode:uiimagerenderingmodealwaysoriginal"; Set the style of text on Tabbaritem (here is the color value for setting text in different states) [Childviewcontroller.tabbaritem settitletextattributes: @{nsforegroundColorattributename:kcolor (117, 117, 117)} Forstate:uicontrolstatenormal]; [Childviewcontroller.tabbaritem settitletextattributes: @{nsforegroundcolorattributename:kcolor (253, 109, 10)} Forstate:uicontrolstateselected]; [Self Addchildviewcontroller:[[uinavigationcontroller alloc] initwithrootviewcontroller:childviewcontroller];} @end
Command + R runs as follows:
Just write it down here, goodnight.
Source: http://download.csdn.net/detail/android_ls/8714209
Imitation Sina Weibo iOS client (v5.2.8)--building the basic framework of the project