AKTabBarController 是一个将自适应和可定制的标签栏用于 iOS。
将依赖项添加到您的 Podfile
platform :ios
pod 'AKTabBarController'
运行 pod install
以安装依赖项。
接下来,导入头文件到您需要使用标签栏控制器的地方
#import "AKTabBarController.h"
// Create and initialize the height of the tab bar to 50px.
_tabBarController = [[AKTabBarController alloc] initWithTabBarHeight:50];
// Adding the view controllers to manage.
[_tabBarController setViewControllers:@[[[FirstViewController alloc] init], [[SecondViewController alloc] init], [[ThirdViewController alloc] init], [[FourthViewController alloc] init]]]];
(在每个视图控制器中)
// Setting the image of the tab.
- (NSString *)tabImageName
{
return @"myImage";
}
// Setting the title of the tab.
- (NSString *)tabTitle
{
return @"Tab";
}
// Ensure to import AKTabController and the category for UIViewController
#import <AKTabBarController.h>
#import <AKTabBarController/UIViewController+AKTabBarController.h>
// It's now possible to access the current AKTabBarController instance.
- (void)viewDidLoad {
[super viewDidLoad];
[self.akTabBarController setTextColor:[UIColor redColor]];
}
注意:在运行 iOS < 5.0 的设备上,self.akTabBarController 返回 nil。
[_tabBarController setMinimumHeightToDisplayTitle:50];
[_tabBarController setTabTitleIsHidden:NO];
当将视图控制器推入 UINavigationController 的视图控制器堆栈中时,可以隐藏标签栏。它的工作方式与原始的 UITabBarController 相同。
[viewController setHidesBottomBarWhenPushed:YES];
// Tab background Image
[_tabBarController setBackgroundImageName:@"noise-dark-gray.png"];
[_tabBarController setSelectedBackgroundImageName:@"noise-dark-blue.png"];
// Tabs top emboss Color
[_tabBarController setTabEdgeColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.8]];
// Tabs colors settings
[_tabBarController setTabColors:@[[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.0], [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0]]]; // MAX 2 Colors
[_tabBarController setSelectedTabColors:@[[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1.0], [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0]]]; // MAX 2 Colors
// Tab stroke Color
[_tabBarController setTabStrokeColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
// Icons color settings
[_tabBarController setIconColors:@[[UIColor colorWithRed:174.0/255.0 green:174.0/255.0 blue:174.0/255.0 alpha:1], [UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1]]]; // MAX 2 Colors
[_tabBarController setSelectedIconColors:@[[UIColor colorWithRed:174.0/255.0 green:174.0/255.0 blue:174.0/255.0 alpha:1], [UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1]]]; // MAX 2 Colors
// Text color
[_tabBarController setTextColor:[UIColor colorWithRed:157.0/255.0 green:157.0/255.0 blue:157.0/255.0 alpha:1.0]];
[_tabBarController setSelectedTextColor:[UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1.0]];
// Text font
[_tabBarController setTextFont:[UIFont fontWithName:@"Chalkduster" size:14]];
// Hide / Show glossy effect on tab icons
[_tabBarController setIconGlossyIsHidden:YES];
// Enable / Disable pre-rendered image mode
[_tabBarController setTabIconPreRendered:YES];
更多信息请参阅 Xcode 示例项目。
Ali Karagoz
AKTabBarController 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。