RDVTabBarController的基本使用 以及tabbar的防止雙點擊方法,rdvtabbarcontroller

來源:互聯網
上載者:User

RDVTabBarController的基本使用 以及tabbar的防止雙點擊方法,rdvtabbarcontroller

RDVTabBarController這個庫寫得相當不錯,所以今天就簡單介紹下它的基本使用,看裡面可以清楚的知道代碼規範的重要性,這個庫的使用方法和官方的相識

:https://github.com/robbdimitrov/RDVTabBarController

首先寫過控制器繼承  RDVTabBarController,

AppDelegate裡面的不多說

例如

1 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];2     3 RDVViewController *rootViewController = [[RDVViewController alloc] init];4 self.window.rootViewController = rootViewController;5 [self.window makeKeyAndVisible];

然後在

RDVViewController.m檔案裡

為了防止tabbar的雙點擊事件,設定代理<RDVTabBarControllerDelegate>,添加標示,用在點擊事件

要設定tabbaritem的字型和圖片,需匯入檔案

#import "RDVTabBarItem.h"

 1 #import "RDVViewController.h" 2 #import "ViewController.h" 3 #import "RDVTabBarItem.h" 4  5 @interface RDVViewController ()<RDVTabBarControllerDelegate> 6 { 7     NSInteger selectedTabBarIiemTag; 8 } 9 @end10 11 @implementation RDVViewController12 13 - (void)viewDidLoad {14     [super viewDidLoad];15     16     ViewController *homeView=[[ViewController alloc]init];17     UINavigationController *NAV1 = [[UINavigationController alloc] initWithRootViewController:homeView];18     19     ViewController *View=[[ViewController alloc]init];20     UINavigationController *NAV2 = [[UINavigationController alloc] initWithRootViewController:View];21     22     ViewController *home=[[ViewController alloc]init];23     UINavigationController *NAV3 = [[UINavigationController alloc] initWithRootViewController:home];24     25     self.viewControllers = @[NAV1,NAV2,NAV3];26     [self customizeTabBarForController:self];27     self.delegate = self;28 }29 30 - (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {31    32     NSArray *tabBarItemImages = @[@"首頁select", @"首頁select",@"首頁select"];33     34     NSInteger index = 0;35     for (RDVTabBarItem *tabberItem in [[tabBarController tabBar] items]) {36         37         tabberItem.title = [NSString stringWithFormat:@"%ld",index+1];38         39         NSDictionary *tabBarTitleUnselectedDic = @{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};40         NSDictionary *tabBarTitleSelectedDic = @{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};41         //修改tabberItem的title顏色42         tabberItem.selectedTitleAttributes = tabBarTitleSelectedDic;43         tabberItem.unselectedTitleAttributes = tabBarTitleUnselectedDic;44         tabberItem.tag = 100+index;45         UIImage *selectedimage = [UIImage imageNamed:@"首頁"];46         UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",47                                                         [tabBarItemImages objectAtIndex:index]]];48         //設定tabberItem的選中和未選中圖片49         [tabberItem setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];50         51         index++;52     }53 }

上面就滿足基本使用方法了,為了防止雙點擊事件,已經設定了代理和tag值

這裡的item不是tabbaritem,而是  rdv_tabBarItem,如果使用了tabBarItem的tag值,那是不存在的,因為這裡設定的是rdv的tabBarItem

 1 #pragma mark - 防止tabbar雙擊 2 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 3     4     if(selectedTabBarIiemTag == viewController.rdv_tabBarItem.tag){ 5          6         return NO; 7          8     }else { 9         10         selectedTabBarIiemTag = viewController.rdv_tabBarItem.tag;11         return YES;12         13     }14 }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.