iOS UITabBar:删除顶部阴影渐变线

问题描述 投票:37回答:13

我实现了一个自定义UITabBar,我仍然在它上面有这个渐变/阴影。我补充道

[self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]];

这只是改变背景但保持阴影渐变。

我究竟做错了什么 ?是否有任何指定摆脱它?

是)我有的 :

我想要的是 :

谢谢。

iphone ios uitabbarcontroller uitabbar
13个回答
36
投票

尝试为UITabBar设置1x1像素透明阴影图像:

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];

0
投票

在视图控制器或视图控制器或BasicViewController中,大多数viewcontrollers在viewDidLoad中继承,只需将这两行放在:

[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bar_background"]];
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparent_shadow"]];

确保[email protected]是1x1或2x2透明图像,[email protected]是图像640x100,因为底部条的高度为50px。

适用于iOS 9.3


0
投票

在viewDidload上试试这个。

override func viewDidLoad() {
        super.viewDidLoad()

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

它对我有用


0
投票

试试这个,** 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]];

**斯威夫特**

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

// or 

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

这是shadowImage的苹果指南。

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

默认值为零。当非零时,显示自定义阴影图像而不是默认阴影图像。要显示自定义阴影,还必须使用-setBackgroundImage设置自定义背景图像:(如果使用默认背景图像,将使用默认阴影图像)。


-1
投票

在iOS 7中 - 这有效:

[self.actionToolbar setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny];
[self.actionToolbar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

希望能帮助别人。


118
投票

回答this question的相似之处...如果你不想搞乱任何一种1x1透明图像,这项工作也是如此:

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

在快速:

UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()

16
投票

迅速

试试这个自定义标签栏吧。它会隐藏水平阴影线。

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

目标C.

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

7
投票

斯威夫特4

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

2
投票

调用[[UITabBar appearance] setShadowImage:]将自定义应用程序中的所有UITabBar实例。

如果您只想自定义一个UITTabBar,您可以这样做:

[self.tabBarController.navigationController.navigationBar setShadowImage:[UIImage new]];

2
投票

这是另一个易于实现的答案:

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

为我工作。


2
投票

只是设置图像它不会删除你必须将它的borderWidth设置为0的阴影线。这是代码

[[UITabBar外观] setShadowImage:[UIImage new]];

[UITabBar外观] .layer.borderWidth = 0.0f;

[UITabBar外观] .clipsToBounds = true;


1
投票

将它放在您的AppDelegate中的didFinishLaunchingWithOptions下:

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

1
投票

我通过以下方法实现了相同的外观。 1.将背景条色调颜色设置为与主父视图背景颜色相同。 2。

this.TabBar.BarStyle = UIBarStyle.BlackOpaque;

我在Xamarin中使用它,请验证Swift语法。

© www.soinside.com 2019 - 2024. All rights reserved.