RDVTabBarController: basic use of rdvtabbarcontroller and tabbar prevention of double click. RDVTabBarController

Source: Internet
Author: User

RDVTabBarController: basic use of rdvtabbarcontroller and tabbar prevention of double click. RDVTabBarController

The RDVTabBarController library is quite well written, so today I will briefly introduce its basic usage and clearly understand the importance of code specifications. The usage of this library is officially known.

: Https://github.com/robbdimitrov/RDVTabBarController

First write the Controller to inherit RDVTabBarController,

Not much in AppDelegate

For example

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];

Then

In the RDVViewController. m file

To prevent tabbar double-click events, set the proxy <RDVTabBarControllerDelegate> and add tags for clicking events.

To set the font and image of tabbaritem, You need to import the file

# Import "RDVTabBarItem. h"

1 # import "RDVViewController. h "2 # import" ViewController. h "3 # import" RDVTabBarItem. h "4 5 @ interface RDVViewController () <strong> 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 = @ [@ "homepage select", @ "homepage select ", @ "homepage 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 =@{ tags: [UIColor blackColor], NSFontAttributeName: [UIFont systemFontOfSize: 15]}; 40 NSDictionary * tabBarTitleSelectedDic =={{}: [UIColor blueColor], NSFontAttributeName: [UIFont systemFontOfSize: 15]}; 41 // Modify the title Color of tabberItem 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 // set the selection of tabberItem and the unselected image 49 [tabberItem setFinishedSelectedImage: selectedimage limit: unselectedimage]; 50 51 index ++; 52} 53}

The above shows the basic usage. To prevent double click events, the proxy and tag value have been set.

Here, the item is not tabbaritem, but rdv_tabBarItem. If the tag value of tabBarItem is used, it does not exist because the tabBarItem of rdv is set here.

1 # pragma mark-prevent tabbar double-clicking 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}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.