Do not use storyboard in Xcode, create Tabbar mode view with pure Xib

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)

If you want to develop a tab-type view of the app, you can use the corresponding template in Xcode

The template is naturally used storyboard that set of things, in order to better understand the xib layout, we do not need to storyboard template to create a Tabbar view of the app.

First step: Create a single View App

Open Xcode, select the single View app template, and create a new project. Then delete all the storyboard files in the project and delete the Viewcontroller class.

Step two: Clear the Start screen

Empty the section about the startup interface in your project:

You can also delete the corresponding 2 attributes in the Info.plist file, but it seems that you can not delete

Step three: Create a new Uiviewcontroller view

Select New Cocoa Touch class, select the new class named REDVC, inherit from Uiviewcontroller, and select Create Xib file. Open the Redvc.m file and add the following method:

-(ID) Initwithnibname: (NSString*) Nibnameornil Bundle: (NSBundle*) nibbundleornil{ Self= [SuperInitwithnibname:nibnameornil Bundle:nibbundleornil];if( Self) { Self. Title= @"Red";UIImage*image = [UIImageimagenamed:@"2.png"]; Cgimageref Imageref = Image. Cgimage; Self. Tabbaritem. Image= [[UIImageImagewithcgimage:imageref scale:2Orientation:uiimageorientationdown] Imagewithrenderingmode:    Uiimagerenderingmodealwaysoriginal]; }return  Self;}

Similarly, create 2 more classes, respectively, GREENVC and WHITEVC, as well as even corresponding to the above method, and make appropriate adjustments.

Fourth step: Modify the App startup method

Open the APPDELEGATE.M file and modify the method as follows:

- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions {//Override point for customization after application launch.     Self. Window= [[UIWindowAlloc]initwithframe:[uiscreen Mainscreen]. Bounds];Uiviewcontroller*VC1 = [[Whitevc alloc]initwithnibname:@"WHITEVC"BundleNil];Uiviewcontroller*VC2 = [[REDVC alloc]initwithnibname:@"REDVC"BundleNil];Uiviewcontroller*VC3 = [[GREENVC alloc]initwithnibname:@"GREENVC"BundleNil]; _tabbarcontroller = [UitabbarcontrollerNEW]; _tabbarcontroller. Viewcontrollers= @[vc1,vc2,vc3]; [ Self. WindowSetrootviewcontroller:_tabbarcontroller]; [ Self. WindowMakekeyandvisible];return YES;}

Ok we basically finished, compile and run the app effect as follows:

Do not use storyboard in Xcode, create Tabbar mode view with pure Xib

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.