Skip to content

Commit

Permalink
iOS 4 Bugs fixed, temporary workaround for gradient-crash on iOS 4
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed May 4, 2012
1 parent 0c672b9 commit a2c5fbf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 18 additions & 7 deletions NGTabBarController/NGTabBar.m
Expand Up @@ -302,15 +302,26 @@ - (void)createGradient {

UIColor *baseColor = self.tintColor;
CGFloat hue, saturation, brightness, alpha;
NSArray *colors = nil;

// TODO: Only works on iOS 5
[baseColor getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
// TODO: This is a temporary workaround because getHue:saturation:brightness:alpha: is iOS 5 and up
// We need a better way of drawing a TabBar-Gradient
if ([baseColor respondsToSelector:@selector(getHue:saturation:brightness:alpha:)]) {
[baseColor getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];

colors = [NSArray arrayWithObjects:
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.2 alpha:alpha],
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.15 alpha:alpha],
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.1 alpha:alpha],
baseColor, nil];
} else {
colors = [NSArray arrayWithObjects:
baseColor,
baseColor,
baseColor,
baseColor, nil];
}

NSArray *colors = [NSArray arrayWithObjects:
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.2 alpha:alpha],
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.15 alpha:alpha],
[UIColor colorWithHue:hue saturation:saturation brightness:brightness+0.1 alpha:alpha],
baseColor, nil];
NSUInteger colorsCount = colors.count;
CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors objectAtIndex:0] CGColor]);

Expand Down
3 changes: 3 additions & 0 deletions NGTabBarController/NGTabBarController.m
Expand Up @@ -253,6 +253,8 @@ - (void)setViewControllers:(NSArray *)viewControllers {
viewController.view.clipsToBounds = YES;
}

[self layout];

if (self.selectedIndex == NSNotFound && _viewControllers.count > 0) {
[self.view addSubview:[[_viewControllers objectAtIndex:0] view]];
self.selectedIndex = 0;
Expand Down Expand Up @@ -573,6 +575,7 @@ - (void)setupTabBarForPosition:(NGTabBarPosition)position {

self.tabBar.frame = frame;
self.tabBar.autoresizingMask = autoresizingMask;
[self.tabBar setNeedsLayout];

for (NSUInteger index = 0; index < self.viewControllers.count; index++) {
UIViewController *viewController = [self.viewControllers objectAtIndex:index];
Expand Down

0 comments on commit a2c5fbf

Please sign in to comment.