Ten minutes to build App mainstream framework _ pure code set up (OC), you do not know the framework
java lovers 2019-06-11 14:28 learning
to build the framework of the mainstream interface
Need the source code can be private letter I
reached effect
Renderings
ps: need the source code can be added to the group, 668 041 364
REVIEW
We play with iPhone applications, there was not found on most of the applications are drawing similar structure, the following TabBar controller can switch sub-controller, Navigation navigation bar above there
we built this article is to discuss the main frame, data temporarily not added
analysis of the basic process of doing the project
Setting up an item of the main frame
(1) to build tabBarController (below a)
(2) re-build the NavigationController (above there is one, and each sub-controller is not the same)
2. Consideration developed embodiment
(1) Storyboard structures (the interface is very less time to use)
(2) to build a pure code (interface over five time use, easy to manage, commercial projects, are normally used in this way)
from 0 to build a mainstream framework (pure code)
1. Preparations
Environmental deployment
Snip20150904_11.png
2. initially set up basic interface
The first step in the design directory (modular + MVC idea, create a basic file and directory files)
modularization create a directory path (usually first created in the true path, again and again to the project)
Custom TabBarController
Snip20150904_4.png
The second step of the code (the root of the controller provided in the window start AppDelegate.m)
- (BOOL) file application: (the UIApplication ) file application didFinishLaunchingWithOptions: (NSDictionary ) launchOptions {
// Create Window 1.
self.window = [[the UIWindow the alloc] the initWithFrame: [The UIScreen mainScreen] .bounds];
// 2. Set the root window control is
CYXTabBarController tabBarVC * = [[CYXTabBarController the alloc] the init];
self.window.rootViewController = tabBarVC;
// display window 3.
[self.window makeKeyAndVisible];
return YES;
}
the third step in creating and adding CYXTabBarController.m sub-controller - (void) the viewDidLoad {
[Super the viewDidLoad];
// add the first controller 1.
// initializes 1.1
CYXOneViewController oneVC = [[CYXOneViewController the alloc] the init];
// add 1.2 put oneVC UINavigationController root controller
UINavigationController NAV1 = [[UINavigationController alloc] initWithRootViewController: oneVC];
// set tabBar title
nav1.title = @ "Home";
[nav1.navigationBar setBackgroundImage: [UIImage imageNamed: @ "commentary_num_bg"] forBarMetrics: UIBarMetricsDefault];
// set the tabBar icon
nav1.tabBarItem.image = [the UIImage the imageNamed: @ "tab_home_icon"];
// set navigationBar title
oneVC.navigationItem.title = @ "Home";
// set the background color (each of these operations may be to control individual sub is doing)
oneVC.view.backgroundColor = [UIColor whiteColor];
// 1.3 UINavigationController to UITabBarController management
[Self addChildViewController: NAV1];
// add the second controller 2.
CYXTwoViewController twoVC = [[CYXTwoViewController the alloc] the init];
UINavigationController NAV2 = [[UINavigationController the alloc] initWithRootViewController: twoVC];
nav2.title = @ "technology";
nav2.tabBarItem.image = [the UIImage the imageNamed: @ "JS"];
twoVC.navigationItem.title = @ "technology";
twoVC.view.backgroundColor = [UIColor blueColor];
[Self addChildViewController : NAV2];
// add the third controller 3.
CYXThreeViewController threeVC = [[CYXThreeViewController the alloc] the init];
the UINavigationController nav3 = [[the UINavigationController the alloc] initWithRootViewController: threeVC];
nav3.title = @ "Bowen";
nav3.tabBarItem.image = [the UIImage the imageNamed: @ "QW"];
threeVC.navigationItem.title = @ "Bowen";
threeVC.view.backgroundColor = [UIColor yellowColor];
[Self addChildViewController : nav3];
// 4. Add the first four controllers
CYXFourViewController fourVC = [[CYXFourViewController alloc] the init];
UINavigationController Nav4 = [[UINavigationController alloc] initWithRootViewController: fourVC];
nav4.title = @ "my rivers and lakes";
Nav4 = .tabBarItem.image [UIImage imageNamed: @ "the User"];
fourVC.navigationItem.title = @ "my rivers and lakes";
fourVC.view.backgroundColor = [UIColor grayColor];
[Self addChildViewController: Nav4];
}
be here we have to take up the framework, is not it simple? The effect is as:
Snip20150904_8.png
But you could not help but Tucao, these are all redundant garbage code is not readable, it is to extract the code below it
the fourth step, extracting duplicate code
because all the code above are written in the inside and viewDidLoad repeat the code too much, resulting in code redundancy, scalability is not high, let's preliminary optimization of the code.
The method of extracting two methods herein, a method of adding all the sub-controllers, and the other is added to each sub-controller
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpAllChildViewController];
}
/**- Add all sub-controller method
* /
- Add all sub-controller method
- (void) setUpAllChildViewController {
// add the first controller 1.
CYXOneViewController oneVC = [[CYXOneViewController the alloc] the init];
[Self setUpOneChildViewController: oneVC Image: [the UIImage the imageNamed: @ "tab_home_icon"] title: @ "Home"];
// 2. Add the second controller
CYXTwoViewController twoVC = [[CYXTwoViewController the alloc] the init];
[Self setUpOneChildViewController: twoVC Image: [the UIImage the imageNamed: @ "JS"] title: @ "technology"];
// 3. Add The third controller
CYXThreeViewController threeVC = [[CYXThreeViewController the alloc] the init];
[Self setUpOneChildViewController: threeVC Image: [the UIImage the imageNamed: @ "QW"] title: @ "Bowen"];
// fourth controller 4. Add
CYXFourViewController fourVC = [[CYXFourViewController the alloc] the init];
[self setUpOneChildViewController: fourVC image: [ UIImage imageNamed: @ "user"] title: @ " My Wild World"];
}
/ **- A method of adding sub-controller
* /
- A method of adding sub-controller
- (void)setUpOneChildViewController:(UIViewController )viewController image:(UIImage )image title:(NSString )title{
UINavigationController navC = [[UINavigationController alloc]initWithRootViewController:viewController];
navC.title = title;
navC.tabBarItem.image = image;
[navC.navigationBar setBackgroundImage:[UIImage imageNamed:@"commentary_num_bg"] forBarMetrics:UIBarMetricsDefault];
viewController.navigationItem.title = title;
[self addChildViewController:navC];
}
1-5 have work experience in the face of popular technical know where to start, we need to overcome technical bottlenecks can add group
In the company to be a long time, I had a very comfortable, but run into a wall when interviewing job-hopping. Need to learn in a short time, you can quit overpaid plus group.
If no work experience, but the base is very solid, the working mechanism of java, common design, common development framework java master skilled, can be added to the group.
Feel that they are cattle B, the general needs can get. But the knowledge learned is not systematic, it is difficult to continue in the field of technology breakthroughs can be added to the group.
Java framework exchange group group number 668 041 364
Ali Java Advanced knowledge points to explain the large cattle live, share knowledge, the six topics above all you teachers of years of work experience to collate and summarize, we took a comprehensive, scientifically establish their own technology systems and technical knowledge! .