zoukankan      html  css  js  c++  java
  • 自定义UITabBar(原创)

    不多说了,直接上代码。复制可用

    CustomerTabBarController.h

    @interface CustomerTabBarController : UITabBarController {
    }
    @end
    
    

    CustomerTabBarController.m

    @implementation CustomerTabBarController
    //@synthesize tabBarTest;
    
    - (void)viewDidLoad {
    
    //方法一,使用颜色自定义UItabBar :
    	/*
        [super viewDidLoad];
    	CGRect frame = CGRectMake(0, 0, 320, 44);
    	UIView *v = [[UIView alloc] initWithFrame:frame];
    	UIColor *c = [[UIColor alloc] initWithRed:0.4 green:0.7 blue:0.3 alpha:1.0];
        v.backgroundColor = c;
        [c release];
    	[self.tabBar insertSubview:v atIndex:0];
        [v release];
    	NSLog(@"view did load");
    	 */
    
    //方法二,使用图片自定义UItabBar :
    	[super viewDidLoad];
    	UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:PACKAGE_FILE_PATH(@"tabbar.png")]];
    	//image.frame = CGRectOffset(image.frame, 0, 5);
    	image.frame = CGRectMake(0, 0, 320,49);
    	[self.tabBar insertSubview:image atIndex:0];
    	[image release];
    }
    @end
    

    调用的地方:

     在*delegate.m众调用:

     

     

    -(void)setupViewControllers
    {
    	UINavigationController* localNavCtroller;
    	NSMutableArray* localViewCtrlArray =  [[NSMutableArray alloc] init];
    	
    	localNavCtroller = [self createNavControllerWrappingView:[HomeViewController class] tabIconName:nil tabTitle:nil];
    	[localViewCtrlArray addObject:localNavCtroller];
    	[localNavCtroller release];
    	
    	localNavCtroller = [self createNavControllerWrappingView:[StoredDataViewController class] tabIconName:nil tabTitle:nil];
    	[localViewCtrlArray addObject:localNavCtroller];
    	[localNavCtroller release];
    	
    	localNavCtroller = [self createNavControllerWrappingView:nil tabIconName:nil tabTitle:nil];
    	[localViewCtrlArray addObject:localNavCtroller];
    	[localNavCtroller release];
    	tabBarController.viewControllers = localViewCtrlArray;
    	[localViewCtrlArray release];
    }
    
    -(UINavigationController *)createNavControllerWrappingView:(Class)controller
    											   tabIconName:(NSString*)iconName
    												  tabTitle:(NSString*)tabTitle
    {
    	UIViewController* viewCtrller = [[controller alloc] init];
    	UINavigationController* theNavCtrller = [[UINavigationController alloc] initWithRootViewController:viewCtrller];
    	theNavCtrller.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    	viewCtrller.tabBarItem.image = [UIImage imageNamed:iconName];
    	viewCtrller.title = NSLocalizedString(tabTitle, @"");
    	[viewCtrller release];
    	return theNavCtrller;
    }

    - (void)applicationDidFinishLaunching:(UIApplication *)application 

    {

    window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

        [windowmakeKeyAndVisible];

     tabBarController = [[CustomerTabBarControlleralloc] init];

    [selfsetupViewControllers];

    [windowaddSubview:tabBarController.view];

    }
  • 相关阅读:
    UML用例图之泛化(generalization)、扩展(extend)和包含(include)关系
    介绍几个在线画流程图的工具
    企业如何招聘到高质量的程序员?
    韩信点兵算法
    扩展VS2010插件通过UML类图,自动生成相关代码
    CSS必须要知道的10个技巧
    T4系列文章之3:T4语法的介绍
    JSON.stringify 语法讲解
    跟我一起学JQuery插件开发
    从VS 2010 自带的2008 SQL数据库中的数据导入到 SQL 2005中
  • 原文地址:https://www.cnblogs.com/moshengren/p/UITabBar.html
Copyright © 2011-2022 走看看