Remove top line from TabBar

2019-01-25 18:06发布

On iOS 10 this code doesn't work in order to remove the tabBar shadow line:

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

Somebody knows, what must I do to remove it?

On iOS 9.3 with this two lines the line is removed, but iOS 10 ignores setShadowImage command.

标签: ios ios10 tabbar
7条回答
爷、活的狠高调
2楼-- · 2019-01-25 18:39

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
查看更多
Viruses.
3楼-- · 2019-01-25 18:40

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-25 18:43

For iOS 10 changed tabbar style to black did the trick

self.tabBarController.tabBar.shadowImage = UIImage()
self.tabBarController.tabBar.barStyle = .Black
查看更多
一夜七次
5楼-- · 2019-01-25 18:43

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
}
查看更多
一夜七次
6楼-- · 2019-01-25 18:46

Just the 2 lines removes the topline

tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
查看更多
仙女界的扛把子
7楼-- · 2019-01-25 18:53

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

查看更多
登录 后发表回答