Remove top line from TabBar

拥有回忆 提交于 2019-11-29 06:06:43

Just the 2 lines removes the topline

tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()

Just try to bellow code for iOS 10 :-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"fondoTabBar"]];
    [UITabBar appearance].layer.borderWidth = 0.0f;
    [UITabBar appearance].clipsToBounds = true;
    return YES;
}

Swift 3.x

UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true

For iOS 10 changed tabbar style to black did the trick

self.tabBarController.tabBar.shadowImage = UIImage()
self.tabBarController.tabBar.barStyle = .Black

Tested on iOS 12.1

override func viewDidLoad() {
    // Remove default border line
    tabBar.shadowImage = UIImage()
    tabBar.backgroundImage = UIImage()
    tabBar.backgroundColor = UIColor.white
}
Alexander Karpov

I had the same problem in ios 10. I fixed this issue just changing the height of UITabBar (by default is 49). Check it here how to change the height.

You should implement the following two methods at the same time:

[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];

If you create your own subclass of UITabBarController, you can set the values in viewDidLoad like this

Swift 3

override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBar.layer.borderWidth = 0
        self.tabBar.clipsToBounds = true
}

It's a shadow image (property) of tabbar. Try following solutions and see.

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 guideline 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).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!