IOS development-Weibo client-basic interface setup (01)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.