iOS development-Weibo client-basic interface Building (01)

Source: Internet
Author: User

1> Creating a program loading interface

-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions

{

//1> Creating a window

self. window = [[UIWindowalloc] initwithframe: [uiscreenmainscreen]. bounds ];

//2> Setting the root controller of a window

uitabbarcontroller *tabbarcontroller = [[uitabbarcontrolleralloc] Init ];

Self. window. Rootviewcontroller = Tabbarcontroller;

//3> display window

[self. windowmakekeyandvisible];

returnyes;

}

2>launchimage Configuration

The detailed configuration of Launchimage is documented in the Contents.json file under the Launchimage.launchimage file:

3> Cancel app icon rendering

4> Hide the status bar when the program loads

You can call [application Setstatusbarhidden in the Didfinishlaunchingwithoptions method After the program is loaded to restore the status bar display. :NO] method;

5> adding Tabbar Controller and its sub-controller

Customize a Tabbarviewcontroller class to inherit the Uitabbarcontroller class to create a custom tabbarview and create a child controller in the Viewdidload method in that class

-(void) viewdidload

{

[Superviewdidload];

// Add sub-controller

uiviewcontroller *home = [[uiviewcontrolleralloc] init];

home. View. BackgroundColor = [uicolorredcolor];

home. Tabbaritem. Title = @ " home ";

home. Tabbaritem. Image = [UIImageimagenamed:@ "Tabbar_home"];

[Home. tabbaritemsetselectedimage: [UIImageimagenamed:@ "tabbar_home_selected" ]];

[self addchildviewcontroller: home];

uiviewcontroller *message = [[uiviewcontrolleralloc] init];

message. View. BackgroundColor = [uicolororangecolor];

Message. Tabbaritem. title = @ " message ";

message. Tabbaritem . Image = [UIImageimagenamed:@ "Tabbar_message_center"];

[Message. Tabbaritem Setselectedimage : [UIImageimagenamed:@ "tabbar_message_center_selected"];

[self addchildviewcontroller: message];

uiviewcontroller *discover = [[uiviewcontrolleralloc] init];

Discover. View. BackgroundColor = [uicolorgreencolor];

Discover. Tabbaritem. title = @ " discovery ";

Discover. Tabbaritem. image = [UIImage imagenamed:@ "Tabbar_discover"];

[Discover. Tabbaritem Setselectedimage : [UIImageimagenamed:@ "tabbar_discover_selected"];

[self addchildviewcontroller:d iscover];

uiviewcontroller *profile = [[uiviewcontrolleralloc] init];

Profile . View. BackgroundColor = [uicolorbluecolor];

Profile. Tabbaritem. title = @ " i ";

Profile . Tabbaritem. Image = [UIImageimagenamed:@ "Tabbar_profile"];

[Profile. tabbaritemsetselectedimage: [UIImageimagenamed:@ "Tabbar_profile_ Selected "];

[self addchildviewcontroller:p rofile];

}

6> Rendering Pictures

In IOS7, the picture of SelectedImage will be rendered blue again, if you want to display the original image, you must cancel the rendering;

To cancel the rendering call method:

SelectedImage = [SelectedImage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

7> Optimization Add sub-controller code

The code to add the sub-controller to Tabbarviewcontroller is optimized to create the following methods:

-(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];

}

Where Zfrandomcolor and iOS7 are custom macros, their macros are defined under the Prefix.pch file:

#ifdef __objc__

#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>

#import <CoreData/CoreData.h>

#define Zfrandomcolor [Uicolor colorwithred:arc4random_uniform ()/255.0 green:arc4random_ Uniform (255.0 blue:arc4random_uniform)/255.0 Alpha:1.0]

#define IOS7 [[Uidevice currentdevice].systemversion Doublevalue] >= 7.0

#endif

Because the Imagewithrenderingmode method is only valid in the IOS7 environment, the code here needs to add conditional judgment statements for system adaptation, by obtaining the system version of the current operating environment to determine whether to compile this method;

8> picture Adaptation

Add a category for UIImage, which is used for system adaptation of Image:

@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.