IOS uses code to build UI interface instances

Source: Internet
Author: User

1. Background

Learning iOS development is almost two months, gig learning mode let me learn relatively fast, but really very tired, daily work progress, in learning

When you need to do a project really a little tired, but see their harvest is worth it. I originally was to do C # development, because the company needs to carry out mobile phone business,

Want to do inside the company, I think it is an opportunity, I chose the iOS.

Learning so that spit groove under the learning Environment of iOS, many times you ask others questions will not return you, especially QQ group, so want to write some more clear tutorials to help those like

I groped like a new scholar to move forward faster into the. Some of the forums I used to go to are awesome. Cocoa China and Code4app These are the two I often go to stroll, and there is

Is the help of the Xcode band, thanks to them for their help.

2. Development environment

My development environment is Xcode 5.1.1,ios SDK 7.1

3. Implementation steps

0> interface effect after implementation

1> New Empty Project

2> Add five Files Mainviewcontroller,firstviewcontroller,secondviewcontroller,thirdviewcontroller,fourlviewcontroller ,

Testviewcontroller respectively to Uitabbarcontroller, Uiviewcontroller,uiviewcontroller,uiviewcontroller,uiviewcontroller,

Uiviewcontroller back five can be arbitrary, is the controller is good, the addition of a good structure is as below.

3> Open the file appdelegate.m file, introduce the MainViewController.h header file, and add the following code

Mainviewcontroller * mainview=[[Mainviewcontroller alloc] init];  Self.window.rootViewController=mainview;
View Code

The files after appdelegate.m are added as follows

4> Open File mainviewcontroller.m, and introduce FirstViewController.h, SecondViewController.h, ThirdViewController.h, FourlViewController.h

Add the following code in the Viewdidload function

[Self creatcontrols];
View Code

When you add a function

//will try to add the controller to Tabbar above- (void) creatcontrols{Firstviewcontroller* firstview=[[Firstviewcontroller alloc] init]; Firstview.tabBarItem.image=[uiimage imagenamed:@"Tab_0.png"]; Firstview.tabBarItem.title=@"Interface One"; Uinavigationcontroller* nvifirst=[[Uinavigationcontroller alloc] init];        [Nvifirst Addchildviewcontroller:firstview]; Secondviewcontroller* secondview=[[Secondviewcontroller alloc]init]; Secondview.tabBarItem.image=[uiimage imagenamed:@"Tab_1.png"]; Secondview.tabBarItem.title=@"Interface Two"; Uinavigationcontroller* nvisecond=[[Uinavigationcontroller alloc] init];        [Nvisecond Addchildviewcontroller:secondview]; Thirdviewcontroller* third=[[Thirdviewcontroller alloc] init]; Third.tabBarItem.image=[uiimage imagenamed:@"Tab_2.png"]; Third.tabBarItem.title=@"Interface Three"; Uinavigationcontroller* nvithird=[[Uinavigationcontroller alloc] init];            [Nvithird Addchildviewcontroller:third]; Fourlviewcontroller* fourview=[[Fourlviewcontroller alloc]init]; Fourview.tabBarItem.image=[uiimage imagenamed:@"Tab_3.png"]; Fourview.tabBarItem.title=@"Interface Four"; Uinavigationcontroller* nvifourview=[[Uinavigationcontroller alloc] init];        [Nvifourview Addchildviewcontroller:fourview]; Nsarray* controls=[Nsarray Arraywithobjects:nvifirst,nvisecond,nvithird,nvifourview, Nil]; Self.viewcontrollers=controls; }
View Code

5. Respectively in FIRSTVIEWCONTROLLER.M, SECONDVIEWCONTROLLER.M, THIRDVIEWCONTROLLER.M, FOURLVIEWCONTROLLER.M is added in the Viewdidload function, respectively.

  self.view.backgroundcolor=[Uicolor Redcolor];  Self.navigationItem.title=@ " beauty ";
View Code

It would be nice to change the text as needed.

6. Introduce the header file TestViewController.h in the firstviewcontroller.m file and add the following code in the Viewdidload function respectively

Uibarbuttonitem * Right=[[uibarbuttonitem alloc]initwithtitle:@ " I want " style: ( uibarbuttonitemstylebordered) target:self Action: @selector (Select:)];      Self.navigationItem.rightBarButtonItem=right;
View Code

Add function again

-(void)Select:(ID) sender{    NSLog (@ " what do you want ")    ; * testview=[[Testviewcontroller alloc] init];  [Self.navigationcontroller Pushviewcontroller:testview animated:yes];}
View Code

7. Open the file testviewcontroller.m and add the following code separately in the Viewdidload function

    UILabel * msg=[[UILabel alloc]init];    Msg.text=@ " haha good ";    [Self.view addsubview:msg];
View Code

8> compile and run to get a Tabbar interface

4. Code Download

Download source code

IOS uses code to build UI interface instances

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.