自訂UITabBar(原創)

來源:互聯網
上載者:User

不多說了,直接上代碼。複製可用

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];

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.