I am changing setSelectionIndicatorImage
and when I run app on iOS 8, I get spacing between image and regular width of tabBar
. Is there a way that I can match height of tab bar with setSelectionIndicatorImage
? Also I get margin of few pixels on left side of first tab and right side of last tab, and I need to cover that with image too when tab is selected.
on didFinishLaunchingWithOptions put this code:
UITabBarController *tabBarContr = (UITabBarController *)self.window.rootViewController;
CGFloat tabBarItemWidth = self.window.rootViewController.view.bounds.size.width / tabBarContr.tabBar.items.count;
CGFloat tabBarItemHeight = CGRectGetHeight(tabBarContr.tabBar.frame);
UIView *selectedBottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tabBarItemWidth, tabBarItemHeight)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = [NSArray arrayWithObjects:
(id)[UIColor blueButton].CGColor,
(id)[UIColor colorWithRed:0.08 green:0.54 blue:1 alpha:1].CGColor,
nil];
gradient.frame = selectedBottomView.bounds;
[selectedBottomView.layer insertSublayer:gradient atIndex:0];
UIGraphicsBeginImageContext(selectedBottomView.bounds.size);
[selectedBottomView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
tabBarContr.tabBar.selectionIndicatorImage = image;
tabBarContr.tabBar.translucent = YES;
tabBarContr.tabBar.tintColor = [UIColor whiteColor];
Note:take imageview instead of gradient
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With