HLMain
概述
本项目简单封装了 iOS 开发常用的基础框架,解决了系统导航栏在导航栏透明度为 0 或隐藏的情况下滑动控制器返回有 bug 的问题。使用当前 APP 市场主流的实现效果,滑动返回时全屏滚动。
HLTabBarController
提供了两种创建方式。
//链式编程
+ (instancetype)tabBarControllerWithAddChildVCsBlock: (void(^)(HLTabBarController *tabBarC))addVCBlock;
//对象方法创建
- (void)addChildVC:(UIViewController *)vc title:(NSString *)title normalImageName:(NSString *)normalImageName selectedImageName:(NSString *)selectedImageName;
具体实现请查看源码,其中包含大量注释,此处不再赘述。
例子
git clone
项目
pod install
查看项目运行结果
运行效果
手动安装安装
- 下载项目,然后将
HLMain
文件夹下的所有文件拖到您的项目中。然后编译看是否有错误。
使用
- 方式一:导入
#import "HLTabBarController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
HLTabBarController *rootVC = [HLTabBarController tabBarControllerWithAddChildVCsBlock:^(HLTabBarController *tabBarC) {
[tabBarC addChildVC:[HotViewController new] title:@"首页" normalImageName:@"home" selectedImageName:@"home_press"];
[tabBarC addChildVC:[TopLineViewController new] title:@"我的" normalImageName:@"me" selectedImageName:@"me_press"];
}];
[rootVC tabBarConfigWithBarBackground:[UIColor colorWithRed:1.00f green:1.00f blue:1.00f alpha:1.00f]
titleFont:[UIFont systemFontOfSize:12]
normalTitleColor:[UIColor colorWithRed:0.56f green:0.60f blue:0.70f alpha:1.00f]
selectedColor:[UIColor colorWithRed:0.21f green:0.39f blue:0.93f alpha:1.00f]];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
return YES;
}
- 方式二 导入你想要使用的控制器。如果只想使用导航栏控制器,可以新建一个导航栏控制器,继承自
HLNavigationController
、HLTabBarController
和HLNavigationController
,它们互不依赖,都可以单独使用。注意:HLNavigationController
依赖的文件有AnimationContoller
和UINavigationBar+Alpha
以及UIImage+Extension
!
CocoaPods 安装
HLMain可以通过CocoaPods获取。要安装它,只需在Podfile中添加以下行
pod 'HLMain'
使用
导入#import "HLTabBarController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
HLTabBarController *rootVC = [HLTabBarController tabBarControllerWithAddChildVCsBlock:^(HLTabBarController *tabBarC) {
[tabBarC addChildVC:[HotViewController new] title:@"首页" normalImageName:@"home" selectedImageName:@"home_press"];
[tabBarC addChildVC:[TopLineViewController new] title:@"我的" normalImageName:@"me" selectedImageName:@"me_press"];
}];
[rootVC tabBarConfigWithBarBackground:[UIColor colorWithRed:1.00f green:1.00f blue:1.00f alpha:1.00f]
titleFont:[UIFont systemFontOfSize:12]
normalTitleColor:[UIColor colorWithRed:0.56f green:0.60f blue:0.70f alpha:1.00f]
selectedColor:[UIColor colorWithRed:0.21f green:0.39f blue:0.93f alpha:1.00f]];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
return YES;
}
作者
许可证
HLMain在MIT许可证下可用。更多信息请参阅LICENSE文件。