2. RootViewController的上半部分加载TabbarController,下半部分是自己画的控件,它用来控制Tabbar Controller加载哪个controller的
3. 把Tabbar controller的Tabbar给hide掉
4. RootViewController的下半部分是自己画的Tabbar,想怎么画就怎么画
大家看我的截图,上面是tabbar controller,它的tabbar已经给隐藏了。
下面是我自己画的自定义tabbar,还很粗糙,最左边的按钮已经可以控制tabbar的切换了。
如何隐藏tabbar控件:
首先要customize UITabBarController,其头文件定义为:
#import
@interface CustomTabbar : UITabBarController {
IBOutlet UITabBar *tabBar1;
}
@property(nonatomic, retain) UITabBar *tabBar1;
-(void) hideExistingTabBar;
@end
在实现文件中加入:
- (void)hideExistingTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar
class]])
{
view.hidden = YES;
break;
}
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super
viewDidLoad];
[self
hideExistingTabBar];
让application delegate默认启动RootViewController
@interface MyTabbarAppDelegate : NSObject
UIWindow *window;
RootViewController *rootController;
}
@property (nonatomic, retain) IBOutlet
UIWindow *window;
@property (nonatomic, retain) IBOutlet
RootViewController *rootController;
实现文件代码:
@implementation MyTabbarAppDelegate
@synthesize window;
@synthesize rootController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
[window
addSubview:rootController.view];
}
RootViewController如何加载tabbar controller:
@class
CustomTabbar;
@interface RootViewController : UIViewController {
CustomTabbar *tabbarController;
}
@property (nonatomic, retain) IBOutlet
CustomTabbar *tabbarController;
- (IBAction) clikcOnFirst:(id)sender;
@end
实现代码:
- (void)viewDidLoad {
[tabbarController.view setFrame:CGRectMake(0, 0, 300, 300)];
[self.view insertSubview:tabbarController.view atIndex:0];
[super
viewDidLoad];
}
RootViewController中的其他控件如何控制tabbar controller的切换:
- (IBAction) clikcOnFirst:(id)sender{
static
int i = 0;
tabbarController.selectedViewController = [ [tabbarController viewControllers] objectAtIndex: i];
++i;
if ( i > 6 )
i = 0;
}