diff --git a/CRNavigationController/CRTabBar.h b/CRNavigationController/CRTabBar.h new file mode 100644 index 0000000..f0e54bb --- /dev/null +++ b/CRNavigationController/CRTabBar.h @@ -0,0 +1,34 @@ +// +// CRTabBar.h +// +// Created by Timothy Costa on 10/7/13. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +@interface CRTabBar : UITabBar +/** + * Determines whether or not the extra color layer should be displayed. + * @param display a BOOL; YES for keeping it visible, NO to hide it. + * @warning this method is not available in the actual implementation, and is only here for demonstration purposes. + */ +- (void)displayColorLayer:(BOOL)display; + +@end diff --git a/CRNavigationController/CRTabBar.m b/CRNavigationController/CRTabBar.m new file mode 100644 index 0000000..6ce18e2 --- /dev/null +++ b/CRNavigationController/CRTabBar.m @@ -0,0 +1,45 @@ +// +// CRTabBar.m +// +// Created by Timothy Costa on 10/7/13. +// + + +#import "CRTabBar.h" +#import "CRNavigationBar.h" + +@interface CRTabBar () +@property (nonatomic, strong) CALayer *colorLayer; +@end +@implementation CRTabBar + +static CGFloat const kDefaultColorLayerOpacity = 0.5f; +static CGFloat const kSpaceToCoverStatusBars = 20.0f; + +- (void)setBarTintColor:(UIColor *)barTintColor { + [super setBarTintColor:barTintColor]; + + if (self.colorLayer == nil) { + self.colorLayer = [CALayer layer]; + self.colorLayer.opacity = kDefaultColorLayerOpacity; + [self.layer addSublayer:self.colorLayer]; + } + + self.colorLayer.backgroundColor = barTintColor.CGColor; +} + +- (void)layoutSubviews { + [super layoutSubviews]; + + if (self.colorLayer != nil) { + self.colorLayer.frame = self.bounds; + [self.layer insertSublayer:self.colorLayer atIndex:1]; + } +} + + +- (void)displayColorLayer:(BOOL)display { + self.colorLayer.hidden = !display; +} + +@end