Jesper Martensson
Jesper Martensson

Reputation: 1248

iOS 7 tabBar-line, how to remove it?

Apple has added a tiny line over the tabBar in iOS 7 which is supposed to work as a shadow or fade between the tabBar and the UI

enter image description here

Since I am using a custom-made tabBar the line is quite irritating. How do you remove it? Please tell me it is possible, otherwise I need to redesign my whole app lol....

/ Regards

*Edit

Sloved my problem with the following line of code:

[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

Upvotes: 43

Views: 15801

Answers (12)

Krunal
Krunal

Reputation: 79636

Try this, ** Objective-C **

//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];

// or 

// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];

** Swift **

//Remove shadow image by assigning nil value.
UITabBar.appearance().shadowImage = nil

// or 

// Assing UIImage instance without image reference
UITabBar.appearance().shadowImage = UIImage()


Here is apple document for shadowImage.

@available(iOS 6.0, *)
open var shadowImage: UIImage?

Default is nil. When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be shown, a custom background image must also be set with -setBackgroundImage: (if the default background image is used, the default shadow image will be used).

Upvotes: 0

E.Chaman
E.Chaman

Reputation: 1

now you can use it, with this line:

self.tabBarController.tabBar.barStyle = UIBarStyleBlack; 

Upvotes: -1

Jeroen
Jeroen

Reputation: 41

In my case I also needed to set a different shadow, in the end the only thing that worked while also setting a custom shadow was to add a single-point high UIView 1 point above the tab bar:

    UIView *whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, -1.0, self.tabBar.frame.size.width, 1.0)];
    whiteLine.backgroundColor = [UIColor whiteColor];
    [self.tabBar addSubview:whiteLine];

Upvotes: 0

Sourabh Sharma
Sourabh Sharma

Reputation: 8322

Swift

Nice simple solution:

Write this below code in your custom tab bar class. Then it will hide horizontal shadow line.

self.tabBar.setValue(true, forKey: "_hidesShadow")

Objective C

[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];

Upvotes: 5

Daxesh Nagar
Daxesh Nagar

Reputation: 1415

 [_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabtarsprnt"]]; //your custom image
[self.tabBarController.tabBar setClipsToBounds:YES];

this code also solved the my issue

Upvotes: 0

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

In iOS 8 the top border can be removed by setting the tab bar style to black in the inspector.

Upvotes: 7

Zoeb S
Zoeb S

Reputation: 705

This worked for me

UIImage* tabBarBackground = [UIImage new];
if(!OSVersionIsAtLeastiOS7())
{
    tabBarBackground = [UIImage imageNamed:@"whitebg"];
}
[[UITabBar appearance] setShadowImage:tabBarBackground];

[[UITabBar appearance] setBackgroundImage:tabBarBackground];

Upvotes: 0

superarts.org
superarts.org

Reputation: 7238

These code works pretty well for me (I don't really have background image for tab bar):

[tab_main.tabBar setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

And I use these code to add a frame too:

UIColor* color_green = UIColorFromRGB(0x348e5b);
tab_main.tabBar.layer.borderWidth = 0.50;
tab_main.tabBar.layer.borderColor = color_green.CGColor;
[[UITabBar appearance] setTintColor:color_green];

Hope that helps.

Upvotes: 14

dineshthamburu
dineshthamburu

Reputation: 1151

self.tabBarController =  [[UITabBarController alloc] init];
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"YOURIMAGE.png"]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

Upvotes: 1

Teja Kumar B
Teja Kumar B

Reputation: 9

Add the following code in AppDelegate.m didFinishLaunchingWithOptions: method

if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
 [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

Upvotes: 0

liancheng.jiang
liancheng.jiang

Reputation: 221

    UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar_bg.png"];
    [[UITabBar appearance] setShadowImage:tabBarBackground];
    [[UITabBar appearance] setBackgroundImage:tabBarBackground];   

Upvotes: 22

bneely
bneely

Reputation: 9093

I'm not seeing anything in the UITabBar API for affecting that separator, but if the separator is within the UITabBar (a UIView subclass), I'd expect you can insert a new one-pixel-high UIView on top of it. You'd have to grab a slice of the image that you want to appear there and draw it in the new view. And I'm not sure if UITabBar would somehow prevent adding the subview or prevent the subview from being on top. But that's where I'd start.

Upvotes: 0

Related Questions