文章出處

首先聲明一下,此文檔是由本人看到別人寫的,然后感覺挺不錯的,為了以后查看方便,再次重新寫一下,請原作者原諒

1,以前基本上都是用系統的tabbar或者是自己完全自定義的,從來都沒有向這兩方面合起來想過

首先創建一個project

其次在AppDelegate.m里面這樣寫道,見

#import "AppDelegate.h"#import "TabbarVC.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.TabbarVC *tabbar = [[TabbarVC alloc]init];tabbar.delegate = self;self.window.backgroundColor = [UIColor whiteColor];self.window.rootViewController = tabbar;return YES;}//設置tabbar上的第三個按鈕不可選-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{return ![viewController isEqual:tabBarController.viewControllers[2]];}

二,TabbarVC.h 為自定義的tabbar

在tabbar的TabbarVC.m中這樣寫道

#import "TabbarVC.h"#import "ViewController.h"#import "ViewController1.h"#import "ViewController2.h"#import "ViewController3.h"#import "ViewController4.h"@interface TabbarVC ()@property (nonatomic, strong) UIView *baseView;@end@implementation TabbarVC- (void)viewDidLoad {[super viewDidLoad];UINavigationController *vC = [self className:@"ViewController" vcTitle:@"消息" tabTitle:@"消息" tabImage:@"release" tabSelectedImage:@"release"];UINavigationController *vC1 = [self className:@"ViewController1" vcTitle:@"通知" tabTitle:@"通知" tabImage:@"U-assn" tabSelectedImage:@"U-assn"];UINavigationController *vC2 = [self className:@"ViewController2" vcTitle:@"人物" tabTitle:@"人物" tabImage:@"U-city" tabSelectedImage:@"U-city"];UINavigationController *vC3 = [self className:@"ViewController3" vcTitle:@"列表" tabTitle:@"列表" tabImage:@"U-me" tabSelectedImage:@"U-me"];UINavigationController *vC4 = [self className:@"ViewController4" vcTitle:@"你好" tabTitle:@"你好" tabImage:@"UU" tabSelectedImage:@"UU"];self.viewControllers = @[vC,vC1,vC2,vC3,vC4];//自定義按鈕UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - 40)/2, 5, 40, 40)];[btn setImage:[UIImage imageNamed:@"point"] forState:UIControlStateNormal];[btn addTarget:self action:@selector(tabBarDidClickPlusButton) forControlEvents:UIControlEventTouchUpInside];[self.tabBar addSubview:btn];}- (UINavigationController *)className:(NSString *)classNamevcTitle:(NSString *)vcTitletabTitle:(NSString *)tabTitletabImage:(NSString *)imagetabSelectedImage:(NSString *)selectedImage{UIViewController *vc = [[NSClassFromString(className) alloc] init];vc.title = vcTitle;vc.tabBarItem.title = tabTitle;vc.tabBarItem.image = [UIImage imageNamed:image];vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];UINavigationController *navgation = [[UINavigationController alloc] initWithRootViewController:vc];return navgation;}- (void)tabBarDidClickPlusButton{_baseView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-250, self.view.frame.size.width, 200)];_baseView.backgroundColor = [UIColor orangeColor];[self.view addSubview:_baseView];UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(romoveBaseView)];[_baseView addGestureRecognizer:tapGesture];}- (void)romoveBaseView{[_baseView removeFromSuperview];}

 

看文倉www.kanwencang.com網友整理上傳,為您提供最全的知識大全,期待您的分享,轉載請注明出處。
歡迎轉載:http://www.kanwencang.com/bangong/20170309/115546.html

文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()