前提 公司没有设计访客视图界面
效果图片
接下来直接上代码
@interface CustomTabBarController : UITabBarController<UITabBarDelegate,UITabBarControllerDelegate>
self.delegate = self;
#pragma mark - 添加tabbaritem
- (void)addTabBarItems{
UITabBar *bar = self.tabBar;
UITabBarItem *homeItem = bar.items[0];
[self setTabBarItem:homeItem image:@"sy_013" selectedImage:@"sy_017" title:@"摩点" tag:1];
UITabBarItem *dynamicItem1 = bar.items[1];
[self setTabBarItem:dynamicItem1 image:@"MD" selectedImage:@"MD2" title:@"项目" tag:2];
UITabBarItem *dynamicItem = bar.items[2];
[self setTabBarItem:dynamicItem image:@"moxi" selectedImage:@"moxi2" title:@"社区" tag:3];
UITabBarItem *inviteFriendsItem = bar.items[3];
[self setTabBarItem:inviteFriendsItem image:@"sy_015" selectedImage:@"sy_019" title:@"朋友" tag:4];
UITabBarItem *personalCenterItem = bar.items[4];
[self setTabBarItem:personalCenterItem image:@"sy_016" selectedImage:@"sy_020" title:@"我的" tag:5];
}
- (void)setTabBarItem:(UITabBarItem *)item image:(NSString *)image selectedImage:(NSString *)selected title:(NSString *)title tag:(NSInteger)tag{
item.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.selectedImage = [[UIImage imageNamed:selected] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.title = title;
item.tag = tag;
[item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];
[item setTitleTextAttributes:@{NSForegroundColorAttributeName: kColor(22, 180, 96)} forState:UIControlStateSelected];
}
#pragma mark - UITabBarControllerDelegate
//这个方法根据官方文档解释意思就是点击下面的tabBar的按钮时候 根据BOOL值来判断是否处于可继续点击状态
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0){
if (viewController.tabBarItem.tag == 3 || viewController.tabBarItem.tag == 4){
if (![Context logined]) {
CKLoginVC *viewFlag = [[CKLoginVC alloc] init];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:viewFlag];
[self presentViewController:navi animated:YES completion:^{
}];
return NO;
}else
{
return YES;
}
} else
{
return YES;
}
}