0
点赞
收藏
分享

微信扫一扫

Sagit.Framework For IOS 自动布局教程:7、底部Tab栏

前言:

IOS的界面,分为:状态栏、导航栏、主界面、底部Tab状态栏。

本篇讲述底部Tab栏的相关操作。

1、Tab栏的高度定义

框架是自动布局和自适应的,所以提供了一个宏定义来表示Tab栏的高度:

Sagit.Framework For IOS 自动布局教程:7、底部Tab栏_导航栏

 

当页面布局,需要用到导航栏高度的时候,就用:STTabHeightPx来使用。

2、Tab栏控制显示与隐藏

-(void)initUI
{
[self needTabBar:NO];
}

参数控制显示或隐藏。

3、Tab栏的基本设置

一些基本属性设置【字体大小、背景色】,框架没有封装,所以下面给出原生的设置方法:

-(void)onInit
{
//状态栏
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];//Start中字颜色为黑,这里改白
[self.view.statusBar backgroundImage:@"circle_bg"];
// [[sagit statusBar] backgroundColor:ColorBlue];
//导航栏
[[[[[[UINavigationBar globalSetting] barTintColor:MainColor] tintColor:ColorWhite] titleTextAttributes:@{NSForegroundColorAttributeName : ColorWhite}]
translucent:NO] backgroundImage:@"circle_bg" stretch:YES];

//设置TabBar
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSFontAttributeName] = STFont(24);// [UIFont systemFontOfSize:12];
attrs[NSForegroundColorAttributeName] = Main_TabFontColor;// [UIColor hex:@"#525050"];

NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
selectedAttrs[NSFontAttributeName] =STFont(24);// [UIFont systemFontOfSize:12];
selectedAttrs[NSForegroundColorAttributeName] = MainColor;

if(AppProdType==4)//IT连是黑色底
{
[[UITabBar appearance] setBarTintColor:ColorBlack];
[UITabBar appearance].translucent = NO;
}
// 拿到UITabBarItem的appearance
UITabBarItem *tabBar = [UITabBarItem appearance];


[tabBar setTitleTextAttributes:attrs forState:UIControlStateNormal];//默认时
[tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];//选择时
tabBar.titlePositionAdjustment = UIOffsetMake(0, -3);

}

4、一些Tab相关示例代码

-(UINavigationController*)create:(NSString*)controllerName title:(NSString*)title icon:(NSString*)icon
{
return [[[[STNew(controllerName) tabTitle:title] tabImage:STString(@"menu_%@",icon)] tabSelectedImage:STString(@"menu_%@_select",icon)] toUINavigationController];
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
Class c= [((UINavigationController*)viewController).viewControllers[0] class];
if([NSStringFromClass(c) eq:@"MyController"])
{
[Sagit.MsgBox alert:STString(@"点击了“我的”菜单!") title:@"温馨提示" okText:@"我知道了"];
}
return YES;
}
- (void)initUI{

UINavigationController *findLove=[self create:@"Find" title:Menu_Love icon:@"love"];
UINavigationController *circle=[self create:@"Topic" title:Menu_Topic icon:@"topic"];
UINavigationController *magic=[self create:@"Magic" title:Menu_Magic icon:@"magic"];
UINavigationController *news=[self create:@"ChatList" title:Menu_Chat icon:@"chat"];
UINavigationController *my=[self create:@"My" title:Menu_My icon:@"my"];
[self setViewControllers:@[findLove,news,magic,circle,my] animated:animated];

}

 

举报

相关推荐

0 条评论