以前写过一篇文章:自定义标签栏,这篇文章提供了另一种自定义标签栏的方式。
部分代码如下,具体的请参考附件。
- (void)addStandardTabView; { JMTabView *tabView = [[[JMTabView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60.)] autorelease]; [tabView setDelegate:self]; [tabView addTabItemWithTitle:@"One" icon:[UIImage imageNamed:@"icon1.png"]]; [tabView addTabItemWithTitle:@"Two" icon:[UIImage imageNamed:@"icon2.png"]]; [tabView addTabItemWithTitle:@"Three" icon:[UIImage imageNamed:@"icon3.png"]]; // You can run blocks by specifiying an executeBlock: paremeter // #if NS_BLOCKS_AVAILABLE // [tabView addTabItemWithTitle:@"One" icon:nil executeBlock:^{NSLog(@"abc");}]; // #endif [tabView setSelectedIndex:0]; [self.view addSubview:tabView]; } - (void)addCustomTabView; { JMTabView *tabView = [[[JMTabView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 60., self.view.bounds.size.width, 60.)] autorelease]; tabView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; [tabView setDelegate:self]; UIImage *standardIcon = [UIImage imageNamed:@"icon3.png"]; UIImage *highlightedIcon = [UIImage imageNamed:@"icon2.png"]; CustomTabItem *tabItem1 = [CustomTabItem tabItemWithTitle:@"One" icon:standardIcon alternateIcon:highlightedIcon]; CustomTabItem *tabItem2 = [CustomTabItem tabItemWithTitle:@"Two" icon:standardIcon alternateIcon:highlightedIcon]; CustomTabItem *tabItem3 = [CustomTabItem tabItemWithTitle:@"Three" icon:standardIcon alternateIcon:highlightedIcon]; CustomTabItem *tabItem4 = [CustomTabItem tabItemWithTitle:@"Four" icon:standardIcon alternateIcon:highlightedIcon]; CustomTabItem *tabItem5 = [CustomTabItem tabItemWithTitle:@"Five" icon:standardIcon alternateIcon:highlightedIcon]; [tabView addTabItem:tabItem1]; [tabView addTabItem:tabItem2]; [tabView addTabItem:tabItem3]; [tabView addTabItem:tabItem4]; [tabView addTabItem:tabItem5]; [tabView setSelectionView:[CustomSelectionView createSelectionView]]; [tabView setItemSpacing:1.]; [tabView setBackgroundLayer:[[[CustomBackgroundLayer alloc] init] autorelease]]; [tabView setSelectedIndex:0]; [self.view addSubview:tabView]; }
效果图: