Permalink
Browse files

TabBarItem Highlight, hide TabBar

  • Loading branch information...
1 parent af720a5 commit 59712779e674ae6fb34ddf7c0a39093d949adead @myell0w myell0w committed Apr 25, 2012
@@ -128,31 +128,33 @@ - (void)layoutSubviews {
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
- CGRect bounds = self.bounds;
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGPoint start;
- CGPoint end;
-
- // draw gradient
- CGContextSaveGState(context);
- CGContextClipToRect(context, bounds);
-
- if (self.position == NGTabBarPositionBottom) {
- start = CGPointMake(bounds.origin.x, bounds.origin.y);
- end = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
- } else if (self.position == NGTabBarPositionTop) {
- start = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
- end = CGPointMake(bounds.origin.x, bounds.origin.y);
- } else if (self.position == NGTabBarPositionLeft) {
- start = CGPointMake(bounds.origin.x + bounds.size.width, bounds.origin.y);
- end = CGPointMake(bounds.origin.x, bounds.origin.y);
- } else if (self.position == NGTabBarPositionRight) {
- start = CGPointMake(bounds.origin.x, bounds.origin.y);
- end = CGPointMake(bounds.origin.x + bounds.size.width, bounds.origin.y);
+ if (self.backgroundImage == nil) {
+ CGRect bounds = self.bounds;
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGPoint start;
+ CGPoint end;
+
+ // draw gradient
+ CGContextSaveGState(context);
+ CGContextClipToRect(context, bounds);
+
+ if (self.position == NGTabBarPositionBottom) {
+ start = CGPointMake(bounds.origin.x, bounds.origin.y);
+ end = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
+ } else if (self.position == NGTabBarPositionTop) {
+ start = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
+ end = CGPointMake(bounds.origin.x, bounds.origin.y);
+ } else if (self.position == NGTabBarPositionLeft) {
+ start = CGPointMake(bounds.origin.x + bounds.size.width, bounds.origin.y);
+ end = CGPointMake(bounds.origin.x, bounds.origin.y);
+ } else if (self.position == NGTabBarPositionRight) {
+ start = CGPointMake(bounds.origin.x, bounds.origin.y);
+ end = CGPointMake(bounds.origin.x + bounds.size.width, bounds.origin.y);
+ }
+
+ CGContextDrawLinearGradient(context, _gradientRef, start, end, 0);
+ CGContextRestoreGState(context);
}
-
- CGContextDrawLinearGradient(context, _gradientRef, start, end, 0);
- CGContextRestoreGState(context);
}
////////////////////////////////////////////////////////////////////////
@@ -37,6 +37,10 @@
/** The duration of the used animation, only taken into account when animation is different from none */
@property (nonatomic, assign) NSTimeInterval animationDuration;
+@property (nonatomic, assign) BOOL tabBarHidden;
+
+- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated;
+
/** Sets the view controllers of the tab bar controller. */
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated;
@@ -302,6 +302,24 @@ - (void)setTabBarItems:(NSArray *)tabBarItems {
}
}
+- (BOOL)tabBarHidden {
+ return self.tabBar.hidden;
+}
+
+- (void)setTabBarHidden:(BOOL)tabBarHidden {
+ [self setTabBarHidden:tabBarHidden animated:NO];
+}
+
+- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated {
+ if (animated) {
+ // TODO:
+ } else {
+ self.tabBar.hidden = YES;
+ self.selectedViewController.view.frame = self.childViewControllerFrame;
+ [self layout];
+ }
+}
+
////////////////////////////////////////////////////////////////////////
#pragma mark - Private
////////////////////////////////////////////////////////////////////////
@@ -563,6 +581,10 @@ - (void)handleItemPressed:(id)sender {
}
- (CGFloat)widthOrHeightOfTabBarForPosition:(NGTabBarPosition)position {
+ if (self.tabBarHidden) {
+ return 0.f;
+ }
+
CGFloat dimension = kNGTabBarControllerDefaultWidth;
// first item is responsible for dimension of tabBar, all must be equal (will not be checked)
@@ -74,6 +74,7 @@ - (void)drawRect:(CGRect)rect {
CGRect bounds = self.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
+ // draw image overlay?
if (self.image != nil) {
CGContextSaveGState(context);
@@ -130,6 +131,27 @@ - (void)drawRect:(CGRect)rect {
CGContextRestoreGState(context);
}
+
+ // draw highlight
+ if (_selectedByUser) {
+ CGRect highlightRect = CGRectInset(rect, 2.f, 2.f);
+ CGFloat cornerRadius = 4.f;
+ CGPoint min = CGPointMake(CGRectGetMinX(highlightRect), CGRectGetMinY(highlightRect));
+ CGPoint mid = CGPointMake(CGRectGetMidX(highlightRect), CGRectGetMidY(highlightRect));
+ CGPoint max = CGPointMake(CGRectGetMaxX(highlightRect), CGRectGetMaxY(highlightRect));
+
+ CGContextSaveGState(context);
+ CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:1.f alpha:0.2f].CGColor);
+ CGContextMoveToPoint(context, min.x, mid.y);
+ CGContextAddArcToPoint(context, min.x, min.y, mid.x, min.y, cornerRadius);
+ CGContextAddArcToPoint(context, max.x, min.y, max.x, mid.y, cornerRadius);
+ CGContextAddArcToPoint(context, max.x, max.y, mid.x, max.y, cornerRadius);
+ CGContextAddArcToPoint(context, min.x, max.y, min.x, mid.y, cornerRadius);
+
+ CGContextClosePath(context);
+ CGContextFillPath(context);
+ CGContextRestoreGState(context);
+ }
}
////////////////////////////////////////////////////////////////////////

0 comments on commit 5971277

Please sign in to comment.