iOS UITabBar:删除顶部阴影渐变线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14371343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS UITabBar : Remove top shadow gradient line
提问by httpete
I implemented a custom UITabBar and I still have this gradient/shadow on top of it. I added
我实现了一个自定义 UITabBar 并且我仍然在它上面有这个渐变/阴影。我加了
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]];
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]];
which is just changing the background but keeping the shadow gradient.
这只是改变背景但保持阴影渐变。
What am I doing wrong ? Is there anything to specify to get rid of it ?
我究竟做错了什么 ?有什么要指定的来摆脱它吗?
What I have :
我拥有的 :
What I want :
我想要的是 :
Thank you.
谢谢你。
采纳答案by Brian Liang
Try setting a 1x1 pixel transparent shadow image for the UITabBar:
尝试为 UITabBar 设置一个 1x1 像素的透明阴影图像:
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];
回答by JakubKnejzlik
Similary in answer for this question... if You don't want to mess with any kind of 1x1 transparent image, this work's too:
类似地回答这个问题......如果你不想弄乱任何类型的 1x1 透明图像,这项工作也是:
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
In swift:
迅速:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
回答by Sourabh Sharma
Swift
迅速
Try this for your custom tab bar. It will hide horizontal shadow line.
为您的自定义标签栏试试这个。它将隐藏水平阴影线。
self.tabBar.setValue(true, forKey: "_hidesShadow")
Objective C
目标 C
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
回答by Alfi
Swift 4
斯威夫特 4
UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true
回答by Miravzal
This code works both iOS 13 and below
此代码适用于 iOS 13 及更低版本
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.backgroundImage = UIImage()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
self.tabBar.standardAppearance = appearance
} else {
self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
}
回答by Nazim Siddiqui
Just be setting image it will not remove the shadow line you have to set it's borderWidth to 0. here is the code
只是设置图像它不会删除你必须将其边框宽度设置为 0 的阴影线。这是代码
[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar 外观] setShadowImage:[UIImage new]];
[UITabBar appearance].layer.borderWidth = 0.0f;
[UITabBar 外观].layer.borderWidth = 0.0f;
[UITabBar appearance].clipsToBounds = true;
[UITabBar 外观].clipsToBounds = true;
回答by dbv
Here's another easy to implement answer:
这是另一个易于实施的答案:
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
Worked for me.
为我工作。
回答by Eric
Calling [[UITabBar appearance] setShadowImage:]
will customise all UITabBar
instances in your app.
调用[[UITabBar appearance] setShadowImage:]
将自定义UITabBar
您的应用程序中的所有实例。
If you want to customize just one UITTabBar
, you can do this:
如果你只想自定义一个UITTabBar
,你可以这样做:
[self.tabBarController.navigationController.navigationBar setShadowImage:[UIImage new]];
回答by DocAsh59
Place this in your AppDelegateunder didFinishLaunchingWithOptions:
把它放在你的AppDelegate下didFinishLaunchingWithOptions:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
回答by Krunal
Try this, ** Objective-C **
试试这个,** 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.
这是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).
默认为零。当非零时,显示自定义阴影图像而不是默认阴影图像。要显示自定义阴影,还必须使用 -setBackgroundImage: 设置自定义背景图像(如果使用默认背景图像,则将使用默认阴影图像)。