ios 底部tabbar 怎么让它默认显示某一个item
1个回答
展开全部
#import "SZMTabBarController.h"
#import "SZMTabBar.h"
#import "SZMHomeViewCtrl.h"
#import "SZMNavigationController.h"
#import "SZMDiscoerViewCtrl.h"
@interface SZMTabBarController ()<SZMTabBarDelegate>
@end
@implementation SZMTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化一个自己的tabbar
SZMTabBar *tabBar = [[SZMTabBar alloc]init];
tabBar.delegate = self;
//通过KVC去设置只读的属性
[self setValue:tabBar forKey:@"tabBar"];
//添加四个控制器
//首页
SZMHomeViewCtrl *homeCtrl = [[SZMHomeViewCtrl alloc]init];
[self addChildVc:homeCtrl title:@"首页" imageName:@"tabbar_home" selImgName:@"tabbar_home_selected"];
UITableViewController *messageCtrl = [[UITableViewController alloc]init];
[self addChildVc:messageCtrl title:@"消息" imageName:@"tabbar_message_center" selImgName:@"tabbar_message_center_selected"];
SZMDiscoerViewCtrl *discoveryCtrl = [[SZMDiscoerViewCtrl alloc]init];
[self addChildVc:discoveryCtrl title:@"发现" imageName:@"tabbar_discover" selImgName:@"tabbar_discover_selected"];
UITableViewController *profileCtrl = [[UITableViewController alloc]init];
[self addChildVc:profileCtrl title:@"我" imageName:@"tabbar_profile" selImgName:@"tabbar_profile_selected"];
}
//设置tabbar的一些属性
- (void)addChildVc:(UIViewController *)Controller title:(NSString *)title imageName:(NSString *)imgName selImgName:(NSString *)selImgName{
Controller.title = title;
Controller.tabBarItem.image = [UIImage imageNamed:imgName];
Controller.tabBarItem.selectedImage = [UIImage imageNamed:selImgName];
self.tabBar.tintColor = [UIColor orangeColor];
SZMNavigationController *navCtrl = [[SZMNavigationController alloc]initWithRootViewController:Controller];
[self addChildViewController:navCtrl];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)TabBar:(SZMTabBar *)TabBar plusBtnDidClick:(UIButton *)btn{
NSLog(@"1");
}
@end
#import "SZMTabBar.h"
#import "SZMHomeViewCtrl.h"
#import "SZMNavigationController.h"
#import "SZMDiscoerViewCtrl.h"
@interface SZMTabBarController ()<SZMTabBarDelegate>
@end
@implementation SZMTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化一个自己的tabbar
SZMTabBar *tabBar = [[SZMTabBar alloc]init];
tabBar.delegate = self;
//通过KVC去设置只读的属性
[self setValue:tabBar forKey:@"tabBar"];
//添加四个控制器
//首页
SZMHomeViewCtrl *homeCtrl = [[SZMHomeViewCtrl alloc]init];
[self addChildVc:homeCtrl title:@"首页" imageName:@"tabbar_home" selImgName:@"tabbar_home_selected"];
UITableViewController *messageCtrl = [[UITableViewController alloc]init];
[self addChildVc:messageCtrl title:@"消息" imageName:@"tabbar_message_center" selImgName:@"tabbar_message_center_selected"];
SZMDiscoerViewCtrl *discoveryCtrl = [[SZMDiscoerViewCtrl alloc]init];
[self addChildVc:discoveryCtrl title:@"发现" imageName:@"tabbar_discover" selImgName:@"tabbar_discover_selected"];
UITableViewController *profileCtrl = [[UITableViewController alloc]init];
[self addChildVc:profileCtrl title:@"我" imageName:@"tabbar_profile" selImgName:@"tabbar_profile_selected"];
}
//设置tabbar的一些属性
- (void)addChildVc:(UIViewController *)Controller title:(NSString *)title imageName:(NSString *)imgName selImgName:(NSString *)selImgName{
Controller.title = title;
Controller.tabBarItem.image = [UIImage imageNamed:imgName];
Controller.tabBarItem.selectedImage = [UIImage imageNamed:selImgName];
self.tabBar.tintColor = [UIColor orangeColor];
SZMNavigationController *navCtrl = [[SZMNavigationController alloc]initWithRootViewController:Controller];
[self addChildViewController:navCtrl];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)TabBar:(SZMTabBar *)TabBar plusBtnDidClick:(UIButton *)btn{
NSLog(@"1");
}
@end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询