1.背景

学习IOS开发也差不多两个月了,赶鸭子上架的学习模式让我学习比较快,但是真心很累,每天有每天的工作进度,在学习的

时候需要边做一个项目真心有点累,但是看到自己的收获还是值得的。自己原来是做C#开发的,由于公司需求想开展手机业务,

想公司内部的人做,我觉得是机遇,我就选择了iOS。

学习了这么就吐槽下ios的学习环境,很多时候你问别人问题得不会回你,特别是QQ群,所以想写一些比较清楚的教程帮助那些像

我一样摸索前进的新学者更快的进入。我比较常去的一些论坛都是很牛逼的。cocoa China和code4app 这两个是我经常去逛的,还有就

是xcode带的帮助,感谢它们提供的帮助。

2.开发环境

我的开发环境是Xcode 5.1.1,IOS SDK 7.1

3.实现步骤

0>实现后的界面效果

      

1>新建空项目

2>添加五个文件MainViewController,FirstViewController,SecondViewController,ThirdViewController,FourlViewController,

TestViewController分别继承至 UITabBarController, UIViewController,UIViewController,UIViewController,UIViewController,

UIViewController 后面五个可以随意,是Controller就好了,添加好的结构就是如下面。

3>打开文件AppDelegate.m文件,引进MainViewController.h 头文件,并添加如下代码

 MainViewController * mainview=[[MainViewController alloc] init];
self.window.rootViewController=mainview;

添加后的AppDelegate.m的文件如下

4>打开文件MainViewController.m,并引进FirstViewController.h ,SecondViewController.h, ThirdViewController.h ,FourlViewController.h

在viewDidLoad 函数添加如下代码

[self creatControls];

在添加函数

//将试图控制器添加到tabbar上面
- (void)creatControls
{
FirstViewController * firstview=[[FirstViewController alloc] init];
firstview.tabBarItem.image=[UIImage imageNamed:@"tab_0.png"];
firstview.tabBarItem.title=@"界面一"; UINavigationController * nvifirst=[[UINavigationController alloc] init];
[nvifirst addChildViewController:firstview]; SecondViewController * secondview=[[SecondViewController alloc]init];
secondview.tabBarItem.image=[UIImage imageNamed:@"tab_1.png"];
secondview.tabBarItem.title=@"界面二";
UINavigationController * nvisecond=[[UINavigationController alloc] init];
[nvisecond addChildViewController:secondview]; ThirdViewController * third=[[ThirdViewController alloc] init];
third.tabBarItem.image=[UIImage imageNamed:@"tab_2.png"];
third.tabBarItem.title=@"界面三";
UINavigationController * nvithird=[[UINavigationController alloc] init];
[nvithird addChildViewController:third]; FourlViewController * fourview=[[FourlViewController alloc]init];
fourview.tabBarItem.image=[UIImage imageNamed:@"tab_3.png"];
fourview.tabBarItem.title=@"界面四";
UINavigationController * nvifourview=[[UINavigationController alloc] init];
[nvifourview addChildViewController:fourview]; NSArray * controls=[NSArray arrayWithObjects:nvifirst,nvisecond,nvithird,nvifourview, nil]; self.viewControllers=controls; }

5.分别在FirstViewController.m ,SecondViewController.m, ThirdViewController.m ,FourlViewController.m的viewDidLoad函数里分别添加

  self.view.backgroundColor=[UIColor redColor];
self.navigationItem.title=@"美女";

根据需要修改文字就好了。

6.在FirstViewController.m文件里引入头文件TestViewController.h,并在viewDidLoad函数里分别添加如下代码

 UIBarButtonItem * right=[[UIBarButtonItem alloc]initWithTitle:@"我想要" style:(UIBarButtonItemStyleBordered) target:self action:@selector(select:)];
self.navigationItem.rightBarButtonItem=right;

再添加函数

- (void)select:(id)sender
{
NSLog(@"你想要什么");
TestViewController * testview=[[TestViewController alloc] init];
[self.navigationController pushViewController: testview animated:YES];
}

7.打开文件TestViewController.m 并在viewDidLoad函数里分别添加如下代码

    UILabel * msg=[[UILabel alloc]init];
msg.text=@"哈哈好样的";
[self.view addSubview:msg];

8>编译运行就能得到一个tabbar的界面

4.代码下载

下载源码

iOS 用代码搭建UI界面实例的更多相关文章

  1. iOS 用代码+Xib搭建UI界面实例

    1.背景 有些我们不能只用代码去构建界面,代码是万能的,你用其他方式可以实现的界面,用代码也一定能 实现,但是我们没必要这样做,有的时候用xib会是更好的选择,代码和xib的优劣地方我们得知道,为了 ...

  2. 使用XML文件和Java代码控制UI界面

    Android推荐使用XML文件设置UI界面,然后用Java代码控制逻辑部分,这体现了MVC思想. MVC全名是Model View Controller,是模型(model)-视图(view)-控制 ...

  3. Android学习笔记(9):使用XML文件和Java代码控制UI界面

    Android推荐使用XML文件设置UI界面.然后用Java代码控制逻辑部分,这体现了MVC思想. MVC全名是Model View Controller.是模型(model)-视图(view)-控制 ...

  4. iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer

    欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平.在这里光玩这些,就显得诚意不足了.特意拓展一下,再加几个UIButton ...

  5. (六十二)纯代码搭建UI

    在Xcode6中,去掉了Empty Application的选项,因此可以通过先创建SingleView,再删除storyboard,并且把工程设置中的main Interface清空. 通过AppD ...

  6. 用代码控制UI界面

           public class MainActivity extends Activity { //当第一次创建Activity时回调该方法 @Override protected void ...

  7. Android学习:代码控制UI界面示例

    package allegro.test2; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; im ...

  8. Spark UI界面原理

    当Spark程序在运行时,会提供一个Web页面查看Application运行状态信息.是否开启UI界面由参数spark.ui.enabled(默认为true)来确定.下面列出Spark UI一些相关配 ...

  9. Android控制UI界面

    ⒈使用XML布局文件控制UI界面[推荐] Android推荐使用XML布局文件来控制视图,这样不仅简单.明了,而且可以将应用的视图控制逻辑从Java或Kotlin代码中分离出来,放入XML文件中控制, ...

随机推荐

  1. ubuntu NTP server 搭建

    ubuntu server ntp时间同步服务器安装及使用一.服务端1 apt-get install ntp 2 安装后默认启动服务,如果没有启动,启动之. /etc/init.d/ntp star ...

  2. 7,SFDC 管理员篇 - 数据模型 - 公式和验证 1

    1,自定义公式 Customize | Your Object | Fields | Add Fields Field SF的公式和Excel的公式差不多,都是支持各种运算和结果 例1,以opport ...

  3. MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合

    一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype:create -DgroupId=me.gacl -DartifactId=spring4-myba ...

  4. html-css实例

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. Python自动化 【第二篇】:Python基础-列表、元组、字典

    本节内容 模块初识 .pyc简介 数据类型初识 数据运算 列表.元组操作 字符串操作 字典操作 集合操作 字符编码与转码 一.模块初识 Python的强大之处在于他有非常丰富和强大的标准库和第三方库, ...

  6. Egret 压缩与解压(jszip)

    一 jszip是什么 二 为什么要用jszip 三 如果使用zip 一 jszip是什么 jszip 是一个 JavaScript 库,可直接在浏览器上创建 zip 压缩档. 二 为什么要用jszip ...

  7. KMeans的图像压缩

    # -*- coding: utf-8 -*- """ Created on Thu Aug 11 18:54:12 2016 @author: Administrato ...

  8. Nginx编译参数大全 configure参数中文详解

    ./configure --help--help 显示本提示信息--prefix=PATH 设定安装目录--sbin-path=PATH 设定程序文件目录--conf-path=PATH 设定配置文件 ...

  9. 关于UID和GID的创建、修改、删除;简要举例

    用户.组和权限 安全3A资源分派 (authentication)认证 (authorization)授权 (accounting)审计 user( 用户) Linux用户:Username/UID ...

  10. Couldn't resolve Mac Server "mymac"

    vs2015创建一个iphone app ,Couldn't resolve Mac Server “mymac” 伤.下班走人