zoukankan      html  css  js  c++  java
  • UITabbarController 实例一

    今天用纯代码来实现UITabbarController的功能,不需要在xib里面使用任何控件 

    本文转自 http://www.999dh.net/article/iphone_ios_art/47.html  转载请注明谢谢!
    1.建立一个 empty application 工程
    2.在 appdelegate.h文件里面实现如下

    @interface XYZAppDelegate : UIResponder <UIApplicationDelegate>

    @property (strong, nonatomic) UIWindow *window;
    @property (retain,nonatomic) UITabBarController * tabController;

    @end


    3.定义3个 viewController   继承自  UIViewController  名字分别为 FirstViewController,SecondViewController,ThirdViewController ,然后分别在 每个view对应的xib文件里面拖上不同的控件(这样做的目的是为了区分在tab 切换的时候已经切换到了不同的view上去)

    4.appdeletate.m文件里面实现如下


    #import "XYZAppDelegate.h"
    #import "FirstViewController.h"
    #import "SecondViewController.h"
    #import "ThirdViewController.h"

    @implementation XYZAppDelegate

    @synthesize window = _window;
    @synthesize tabController;

    - (void)dealloc
    {
        [_window release];
        [super dealloc];
    }

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        
        FirstViewController * fristView = [[FirstViewController alloc] init];
        SecondViewController* secView = [[SecondViewController alloc] init];
        ThirdViewController * thirdView = [[ThirdViewController alloc] init];
        UITableViewController * forthView = [[UITableViewController alloc] init];
        
        NSArray * array = [[NSArray alloc]initWithObjects:fristView,secView,thirdView, forthView,nil];
        
        tabController = [[UITabBarController alloc]init];
        
        tabController.viewControllers = array;
        
        [[tabController.tabBar.items objectAtIndex:0]setTitle:@"AAA"];
        [[tabController.tabBar.items objectAtIndex:1]setTitle:@"BBBB"];
        [[tabController.tabBar.items objectAtIndex:2]setTitle:@"CCCC"];
        [[tabController.tabBar.items objectAtIndex:3]setTitle:@"DDDD"];
        
        [[tabController.tabBar.items objectAtIndex:0]setImage:[UIImage imageNamed:@"001.png"]];
        [[tabController.tabBar.items objectAtIndex:1]setImage:[UIImage imageNamed:@"002.png"]];
        [[tabController.tabBar.items objectAtIndex:2]setImage:[UIImage imageNamed:@"003.png"]];
        [[tabController.tabBar.items objectAtIndex:3]setImage:[UIImage imageNamed:@"004.png"]];
        
        tabController.selectedIndex = 1;
        
        [self.window addSubview:tabController.view];
        
        
        [array release];
        
        
        [self.window makeKeyAndVisible];
        return YES;
    }


    实现后的效果如图所示  

  • 相关阅读:
    linux运维之分析系统负载及运行状况
    linux运维之分析日志相关命令(1)
    centos7修改网卡名称为eth0
    LANMP环境编译参数查看方法
    自动化部署之搭建yum仓
    浙大 PAT 乙级 1001-1075 目录索引
    更改docker服务网段分配地址
    MySQL主从复制(Replication for Backup)
    MySQL读写分离-简单思考
    NGINX负载均衡缓存配置
  • 原文地址:https://www.cnblogs.com/rollrock/p/2843756.html
Copyright © 2011-2022 走看看