1> create a program loading Interface
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
// 1> Create a window
Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen]. bounds];
// 2> set the root controller of the window
UITabBarController * tabBarController = [[UITabBarControlleralloc] init];
Self. window. rootViewController = tabBarController;
// 3> display window
[Self. windowmakeKeyAndVisible];
ReturnYES;
}
2> LaunchImage Configuration
The Contents. json file in the LaunchImage. launchimage file records the detailed configuration of LaunchImage:
3> cancel APP icon Rendering
4> hide the status bar during program loading
To restore the status bar display after the program is loaded, you can call the [application setStatusBarHidden: NO] Method in the didfinishlaunchingwitexceptions method;
5> Add a TabBar Controller and Its subcontrollers
A custom TabBarViewController class inherits the UITabBarController class to create a custom TabBarView, and creates a subcontroller in the viewDidLoad method of this class.
-(Void) viewDidLoad
{
[SuperviewDidLoad];
// Add a sub-Controller
UIViewController * home = [[UIViewControlleralloc] init];
Home. view. backgroundColor = [UIColorredColor];
Home. tabBarItem. title = @ "Homepage ";
Home. tabBarItem. image = [UIImageimageNamed: @ "tabbar_home"];
[Home. tabBarItemsetSelectedImage: [UIImageimageNamed: @ "tabbar_home_selected"];
[SelfaddChildViewController: home];
UIViewController * message = [[UIViewControlleralloc] init];
Message. view. backgroundColor = [UIColororangeColor];
Message. tabBarItem. title = @ "message ";
Message. tabBarItem. image = [UIImageimageNamed: @ "tabbar_message_center"];
[Message. tabBarItemsetSelectedImage: [UIImageimageNamed: @ "tabbar_message_center_selected"];
[SelfaddChildViewController: message];
UIViewController * discover = [[UIViewControlleralloc] init];
Discover. view. backgroundColor = [UIColorgreenColor];
Discover. tabBarItem. title = @ "";
Discover. tabBarItem. image = [UIImage imageNamed: @ "tabbar_discover"];
[Discover. tabBarItemsetSelectedImage: [UIImageimageNamed: @ "tabbar_discover_selected"];
[SelfaddChildViewController: discover];
UIViewController * profile = [[UIViewControlleralloc] init];
Profile. view. backgroundColor = [UIColorblueColor];
Profile. tabBarItem. title = @ "me ";
Profile. tabBarItem. image = [UIImageimageNamed: @ "tabbar_profile"];
[Profile. tabBarItemsetSelectedImage: [UIImageimageNamed: @ "tabbar_profile_selected"];
[SelfaddChildViewController: profile];
}
6> rendering Images
In iOS7, The selectedImage image is rendered blue again. To display the source image, you must cancel the rendering;
Method for canceling rendering call:
SelectedImage = [selectedImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
7> optimized addition of sub-controller code
Optimize the code of adding a sub-controller to TabBarViewController by using the following method:
-(Void) addOneChildViewController :( UIViewController *) viewController withTitle :( NSString *) title imageName :( NSString *) imageName selectedImageName :( NSString *) selectedImageName
{
ViewController. view. backgroundColor = ZFRandomColor;
ViewController. tabBarItem. title = title;
ViewController. tabBarItem. image = [UIImage imageNamed: imageName];
UIImage * image = [UIImage imageNamed: selectedImageName];
If (iOS7 ){
Image = [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
}
[ViewController. tabBarItem setSelectedImage: image];
[Self addChildViewController: viewController];
}
ZFRandomColor and iOS7 are custom macros, which are defined in the Prefix. pch file:
# Ifdef _ OBJC __
# Import <UIKit/UIKit. h>
# Import <Foundation/Foundation. h>
# Import <CoreData/CoreData. h>
# Define ZFRandomColor [UIColor colorWithRed: arc4random_uniform (256)/255.0 green: arc4random_uniform (256)/255.0 blue: arc4random_uniform (256)/255.0 alpha: 1.0]
# Define iOS7 [[UIDevice currentDevice]. systemVersion doubleValue]> = 7.0
# Endif
The imageWithRenderingMode method is valid only in the iOS7 environment. Therefore, the code needs to add a condition judgment statement to adapt to the system. You can determine whether to compile this method by obtaining the system version of the current running environment;
8> image adaptation
Add a category for UIImage for image system adaptation:
@ Implementation UIImage (Extension)
+ (UIImage *) imageWithName :( NSString *) imageName
{
UIImage * image = nil;
If (iOS7 ){
NSString * name = [imageName stringByAppendingString: @ "_ os7"];
Image = [UIImage imageNamed: name];
}
If (! Image ){
Image = [UIImage imageNamed: imageName];
}
Return image;
}
@ End