diff --git a/Example/Classes/App Delegate/RDVAppDelegate.m b/Example/Classes/App Delegate/RDVAppDelegate.m index 7211dbe..0071410 100644 --- a/Example/Classes/App Delegate/RDVAppDelegate.m +++ b/Example/Classes/App Delegate/RDVAppDelegate.m @@ -87,33 +87,32 @@ - (void)customizeTabBarForController:(RDVTabBarController *)tabBarController { - (void)customizeInterface { UINavigationBar *navigationBarAppearance = [UINavigationBar appearance]; - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { - [navigationBarAppearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_background_tall"] - forBarMetrics:UIBarMetricsDefault]; - } else { - [navigationBarAppearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_background"] - forBarMetrics:UIBarMetricsDefault]; - - NSDictionary *textAttributes = nil; + UIImage *backgroundImage = nil; + NSDictionary *textAttributes = nil; + + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { + backgroundImage = [UIImage imageNamed:@"navigationbar_background_tall"]; - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { - textAttributes = @{ - NSFontAttributeName: [UIFont boldSystemFontOfSize:20], - NSForegroundColorAttributeName: [UIColor blackColor], - }; - } else { + textAttributes = @{ + NSFontAttributeName: [UIFont boldSystemFontOfSize:18], + NSForegroundColorAttributeName: [UIColor blackColor], + }; + } else { #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 - textAttributes = @{ - UITextAttributeFont: [UIFont boldSystemFontOfSize:20], - UITextAttributeTextColor: [UIColor blackColor], - UITextAttributeTextShadowColor: [UIColor clearColor], - UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero], - }; -#endif - } + backgroundImage = [UIImage imageNamed:@"navigationbar_background"]; - [navigationBarAppearance setTitleTextAttributes:textAttributes]; + textAttributes = @{ + UITextAttributeFont: [UIFont boldSystemFontOfSize:18], + UITextAttributeTextColor: [UIColor blackColor], + UITextAttributeTextShadowColor: [UIColor clearColor], + UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero], + }; +#endif } + + [navigationBarAppearance setBackgroundImage:backgroundImage + forBarMetrics:UIBarMetricsDefault]; + [navigationBarAppearance setTitleTextAttributes:textAttributes]; } @end diff --git a/Example/Classes/Controllers/RDVFirstViewController.m b/Example/Classes/Controllers/RDVFirstViewController.m index 4665926..e858f1e 100644 --- a/Example/Classes/Controllers/RDVFirstViewController.m +++ b/Example/Classes/Controllers/RDVFirstViewController.m @@ -42,6 +42,16 @@ - (void)viewDidLoad { [super viewDidLoad]; [[self rdv_tabBarItem] setBadgeValue:@"3"]; + + if (self.rdv_tabBarController.tabBar.translucent) { + UIEdgeInsets insets = UIEdgeInsetsMake(0, + 0, + CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), + 0); + + self.tableView.contentInset = insets; + self.tableView.scrollIndicatorInsets = insets; + } } - (NSUInteger)supportedInterfaceOrientations { @@ -80,13 +90,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 10; + return 15; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [[self rdv_tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", indexPath.row+1]]; + + [[self rdv_tabBarController] setTabBarHidden:!self.rdv_tabBarController.tabBarHidden animated:YES]; } @end diff --git a/Example/Classes/Controllers/RDVSecondViewController.m b/Example/Classes/Controllers/RDVSecondViewController.m index 14d002b..0793b70 100644 --- a/Example/Classes/Controllers/RDVSecondViewController.m +++ b/Example/Classes/Controllers/RDVSecondViewController.m @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "RDVSecondViewController.h" +#import "RDVTabBarController.h" @implementation RDVSecondViewController @@ -36,6 +37,20 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil #pragma mark - View lifecycle +- (void)viewDidLoad { + [super viewDidLoad]; + + if (self.rdv_tabBarController.tabBar.translucent) { + UIEdgeInsets insets = UIEdgeInsetsMake(0, + 0, + CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), + 0); + + self.tableView.contentInset = insets; + self.tableView.scrollIndicatorInsets = insets; + } +} + - (NSUInteger)supportedInterfaceOrientations { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationMaskAll; @@ -72,7 +87,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 10; + return 15; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Example/Classes/Controllers/RDVThirdViewController.m b/Example/Classes/Controllers/RDVThirdViewController.m index 91ca241..f93e129 100644 --- a/Example/Classes/Controllers/RDVThirdViewController.m +++ b/Example/Classes/Controllers/RDVThirdViewController.m @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "RDVThirdViewController.h" +#import "RDVTabBarController.h" @implementation RDVThirdViewController @@ -36,6 +37,20 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil #pragma mark - View lifecycle +- (void)viewDidLoad { + [super viewDidLoad]; + + if (self.rdv_tabBarController.tabBar.translucent) { + UIEdgeInsets insets = UIEdgeInsetsMake(0, + 0, + CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), + 0); + + self.tableView.contentInset = insets; + self.tableView.scrollIndicatorInsets = insets; + } +} + - (NSUInteger)supportedInterfaceOrientations { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationMaskAll; @@ -72,7 +87,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 10; + return 15; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/RDVTabBarController.podspec b/RDVTabBarController.podspec index ac400e5..3de6f56 100644 --- a/RDVTabBarController.podspec +++ b/RDVTabBarController.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = "RDVTabBarController" - s.version = "1.1.5" + s.version = "1.1.6" s.summary = "Highly customizable tabBar and tabBarController for iOS" s.description = "RDVTabBarController is iPad and iPhone compatible. Supports landscape and portrait orientations and can be used inside UINavigationController." s.homepage = "https://github.com/robbdimitrov/RDVTabBarController" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Robert Dimitrov" => "robert_dimitrov@me.com" } s.platform = :ios, '5.0' - s.source = { :git => "https://github.com/robbdimitrov/RDVTabBarController.git", :tag => "v1.1.5" } + s.source = { :git => "https://github.com/robbdimitrov/RDVTabBarController.git", :tag => "v1.1.6" } s.source_files = 'RDVTabBarController', 'RDVTabBarController/**/*.{h,m}' s.framework = 'UIKit', 'CoreGraphics', 'Foundation' s.requires_arc = true diff --git a/RDVTabBarController/RDVTabBar.h b/RDVTabBarController/RDVTabBar.h index 546f8fe..6c24067 100755 --- a/RDVTabBarController/RDVTabBar.h +++ b/RDVTabBarController/RDVTabBar.h @@ -77,4 +77,9 @@ */ - (CGFloat)minimumContentHeight; +/* + * Enable or disable tabBar translucency. Default is NO. + */ +@property (nonatomic, getter=isTranslucent) BOOL translucent; + @end diff --git a/RDVTabBarController/RDVTabBar.m b/RDVTabBarController/RDVTabBar.m index c194681..8da27e4 100755 --- a/RDVTabBarController/RDVTabBar.m +++ b/RDVTabBarController/RDVTabBar.m @@ -55,8 +55,9 @@ - (id)init { - (void)commonInitialization { _backgroundView = [[UIView alloc] init]; - [_backgroundView setBackgroundColor:[UIColor lightGrayColor]]; [self addSubview:_backgroundView]; + + [self setTranslucent:NO]; } - (void)layoutSubviews { @@ -155,4 +156,17 @@ - (void)setSelectedItem:(RDVTabBarItem *)selectedItem { [_selectedItem setSelected:YES]; } +#pragma mark - Translucency + +- (void)setTranslucent:(BOOL)translucent { + _translucent = translucent; + + CGFloat alpha = (translucent ? 0.9 : 1.0); + + [_backgroundView setBackgroundColor:[UIColor colorWithRed:245/255.0 + green:245/255.0 + blue:245/255.0 + alpha:alpha]]; +} + @end diff --git a/RDVTabBarController/RDVTabBarController.m b/RDVTabBarController/RDVTabBarController.m index 5cbba47..dbe8406 100755 --- a/RDVTabBarController/RDVTabBarController.m +++ b/RDVTabBarController/RDVTabBarController.m @@ -53,23 +53,9 @@ - (void)viewDidLoad { - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - CGSize viewSize = self.view.frame.size; - CGFloat tabBarHeight = CGRectGetHeight([[self tabBar] frame]); - CGFloat tabBarStartingY = viewSize.height; - CGFloat contentViewHeight = viewSize.height; - if (!tabBarHeight) { - tabBarHeight = 49; - } - - if (![self isTabBarHidden]) { - tabBarStartingY = viewSize.height - tabBarHeight; - contentViewHeight = viewSize.height - ([[self tabBar] minimumContentHeight] ?: tabBarHeight); - } - - [[self tabBar] setFrame:CGRectMake(0, tabBarStartingY, viewSize.width, tabBarHeight)]; - [[self contentView] setFrame:CGRectMake(0, 0, viewSize.width, contentViewHeight)]; - [self setSelectedIndex:[self selectedIndex]]; + + [self setTabBarHidden:NO animated:NO]; } - (NSUInteger)supportedInterfaceOrientations { @@ -179,18 +165,19 @@ - (UIView *)contentView { } - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated { - if (_tabBarHidden == hidden) { - return; - } - _tabBarHidden = hidden; __weak RDVTabBarController *weakSelf = self; void (^block)() = ^{ CGSize viewSize = weakSelf.view.frame.size; - CGRect contentViewFrame = [[weakSelf contentView] frame]; - CGRect tabBarFrame = [[weakSelf tabBar] frame]; + CGFloat tabBarStartingY = viewSize.height; + CGFloat contentViewHeight = viewSize.height; + CGFloat tabBarHeight = CGRectGetHeight([[weakSelf tabBar] frame]); + + if (!tabBarHeight) { + tabBarHeight = 49; + } if (![weakSelf parentViewController]) { if (UIInterfaceOrientationIsLandscape([weakSelf interfaceOrientation])) { @@ -198,24 +185,16 @@ - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated { } } - CGFloat tabBarStartingY = viewSize.height; - CGFloat contentViewHeight = viewSize.height; - if (!hidden) { - tabBarStartingY = viewSize.height - CGRectGetHeight(tabBarFrame); - contentViewHeight = viewSize.height - [[weakSelf tabBar] minimumContentHeight]; + tabBarStartingY = viewSize.height - tabBarHeight; + if (![[weakSelf tabBar] isTranslucent]) { + contentViewHeight -= ([[weakSelf tabBar] minimumContentHeight] ?: tabBarHeight); + } [[weakSelf tabBar] setHidden:NO]; } - [[weakSelf tabBar] setFrame:CGRectMake(CGRectGetMinX(tabBarFrame), - tabBarStartingY, - CGRectGetWidth(tabBarFrame), - CGRectGetHeight(tabBarFrame))]; - - [[weakSelf contentView] setFrame:CGRectMake(CGRectGetMinX(contentViewFrame), - CGRectGetMinY(contentViewFrame), - CGRectGetWidth(contentViewFrame), - contentViewHeight)]; + [[weakSelf tabBar] setFrame:CGRectMake(0, tabBarStartingY, viewSize.width, tabBarHeight)]; + [[weakSelf contentView] setFrame:CGRectMake(0, 0, viewSize.width, contentViewHeight)]; }; void (^completion)(BOOL) = ^(BOOL finished){ diff --git a/RDVTabBarController/RDVTabBarItem.m b/RDVTabBarController/RDVTabBarItem.m index cf74d1f..52835e0 100755 --- a/RDVTabBarController/RDVTabBarItem.m +++ b/RDVTabBarController/RDVTabBarItem.m @@ -62,10 +62,12 @@ - (id)init { - (void)commonInitialization { // Setup defaults + [self setBackgroundColor:[UIColor clearColor]]; + _title = @""; _titlePositionAdjustment = UIOffsetZero; - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { _unselectedTitleAttributes = @{ NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: [UIColor blackColor], @@ -126,7 +128,7 @@ - (void)drawRect:(CGRect)rect { imageSize.width, imageSize.height)]; } else { - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { titleSize = [_title boundingRectWithSize:CGSizeMake(frameSize.width, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: titleAttributes[NSFontAttributeName]} @@ -182,7 +184,7 @@ - (void)drawRect:(CGRect)rect { if ([[self badgeValue] length]) { CGSize badgeSize = CGSizeZero; - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { badgeSize = [_badgeValue boundingRectWithSize:CGSizeMake(frameSize.width, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [self badgeTextFont]} @@ -215,7 +217,7 @@ - (void)drawRect:(CGRect)rect { CGContextSetFillColorWithColor(context, [[self badgeTextColor] CGColor]); - if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) { + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { NSMutableParagraphStyle *badgeTextStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; [badgeTextStyle setLineBreakMode:NSLineBreakByWordWrapping]; [badgeTextStyle setAlignment:NSTextAlignmentCenter]; diff --git a/README.md b/README.md index 15c908f..817dc7f 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,11 @@ Add the items from `RDVTabBarController` directory to your project. If you don't ## Example Usage -Initialize RDVTabBarController: +#### Initialize RDVTabBarController -``` +The initialization is similar to the one for `UITabBarController`. Create an instance of the `tabBarController` and initialize its `viewControllers`. + +```objective-c UIViewController *firstViewController = [[RDVFirstViewController alloc] init]; UIViewController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; @@ -42,9 +44,10 @@ RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init]; self.viewController = tabBarController; ``` -Customize RDVTabBarController: +#### Customize RDVTabBarController +Each `RDVTabBarItem` has `selectedBackground`, `unselectedBackground` and corresponding properties for the icons: `selectedImage` and `unselectedImage`. -``` +```objective-c UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"]; UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"]; NSArray *tabBarItemImages = @[@"first", @"second", @"third"]; @@ -66,6 +69,39 @@ for (RDVTabBarItem *item in [[tabBarController tabBar] items]) { } ``` +#### Make the tab bar transparent + +`RDVTabBar` has `transparent` property which determines how it is going to be handled. + +```objective-c +RDVTabBar *tabBar = tabBarController.tabBar; + +// After the tabBarController initialization +tabBar.translucent = YES; + +// Customizing the tabBar background +tabBar.backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 + green:245/255.0 + blue:245/255.0 + alpha:0.9]]; + +// Inside the tabbed viewControllers +- (void)viewDidLoad { + [super viewDidLoad]; + + ... + + if (self.rdv_tabBarController.tabBar.translucent) { + CGFloat tabBarHeight = CGRectGetHeight(self.rdv_tabBarController.tabBar.frame); + UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, tabBarHeight, 0); + + self.tableView.contentInset = insets; + self.tableView.scrollIndicatorInsets = insets; + } +} + +``` + ## Requirements * ARC