Reputation: 848
Createa a project with custom TabBar
, its work perfect in iOS
up to 9 but in iOS 10
i have a problem with TabBar
line on top of the TabBar
.
Tried following code:
UITabBarController *Tabbar;
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
its work in iOS9
not in iOS10
.
I tried to apply this to the TabBar
1) Try :
[Tabbar.tabBar setShadowImage:[[UIImage alloc] init]];
Tabbar.tabBar.layer.borderWidth = 0.0f;
Tabbar.tabBar.layer.borderColor =[UIColor clearColor].CGColor;
Tabbar.tabBar.layer.backgroundColor=[UIColor clearColor].CGColor;
Tabbar.tabBar.tintColor=CLEAR_COLOR;
Tabbar.tabBar.barTintColor=CLEAR_COLOR;
2)Try :
CALayer * superLayer = [UITabBar appearance].layer;
CALayer * layer = [CALayer layer];
layer.bounds = CGRectMake (0.0f, 0.0f, 62.0f, 56.0f);
layer.contents = (id) [UIImage imageNamed: @"tras_tabbg-min"].CGImage;
layer.anchorPoint = CGPointMake (0.5f, 1.0f);
layer.position = CGPointMake (superLayer.bounds.size.width / 2.0f, superLayer.bounds.size.height);
layer.zPosition = 1.0f;
[[UITabBar appearance].layer addSublayer: layer];
3) Try : (crash the app)
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
*4) Try: *
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourImageName"]];
[UITabBar appearance].layer.borderWidth = 0.0f;
[UITabBar appearance].clipsToBounds = true;
Output :
I want Border Hear also. this is a background Image.
Note : I want background Image on tabbar it is not nil or clear
If Any solution kindly reply.
Upvotes: 0
Views: 1273
Reputation: 1
iOS 10:
UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true
Upvotes: 0
Reputation: 1
Create a custom UITabBar Class & override layoutSubviews method as below:
-(void)layoutSubviews{
[super layoutSubviews];
for (UIView *view in self.subviews){
if([NSStringFromClass([view class]) isEqualToString:@"_UIBarBackground"]){
if(view.subviews.count>1){
[view.subviews[1] removeFromSuperview];
}
}
}
}
enjoy!
Upvotes: 0
Reputation: 51
if >= iOS 10
tabBar.barStyle = UIBarStyle.black
else < iOS 10:
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
Upvotes: 5
Reputation: 3082
I think this will work. Is working for iOS 9. Try it.
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
If the above solution doesn't worked. Try this. This code is tested in iOS 10 and 10.1, its working fine.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourImageName"]];
[UITabBar appearance].layer.borderWidth = 0.0f;
[UITabBar appearance].clipsToBounds = true;
return YES;
}
Upvotes: 0
Reputation: 5135
This line is comming from your custom image or color
self.tabBar.backgroundImage = nil
self.tabBar.shadowImage = nil
and Check view behid tabBar
Upvotes: 0
Reputation: 874
In the view did load method of custom tab bar use this code.(swift 3) Convert this to objective c
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
}
}
Upvotes: 0