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

Iphone iOS UITabBar:删除顶部阴影渐变线,iphone,ios,uitabbarcontroller,uitabbar,Iphone,Ios,Uitabbarcontroller,Uitabbar,我实现了一个自定义的UITabBar,我仍然在上面有这个渐变/阴影。 我补充说 [self.tabBar setBackgroundImage:[UIImage ImageName:@“navbbottom.png”] 这只是改变背景,但保持阴影渐变 我做错了什么?有没有什么具体的方法来摆脱它 我所拥有的: 我想要的是: 谢谢。尝试为UITabBar设置1x1像素的透明阴影图像: [[UITabBar appearance] setShadowImage:[UIImage imageName

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

[self.tabBar setBackgroundImage:[UIImage ImageName:@“navbbottom.png”]

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

我做错了什么?有没有什么具体的方法来摆脱它

我所拥有的:

我想要的是:


谢谢。

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

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];
同样地回答。。。如果您不想弄乱任何类型的1x1透明图像,这项工作也是:

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

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

调用
[[uitabar外观]setShadowImage:
将自定义应用程序中的所有
uitabar
实例

如果只想自定义一个
uitabbar
,可以执行以下操作:

[self.tabBarController.navigationController.navigationBar setShadowImage:[UIImage new]];
在iOS 7中,这项工作:

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

希望这对某人有所帮助。

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

[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
为我工作。

Swift

为您的自定义选项卡栏尝试此选项。它将隐藏水平阴影线

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

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

将其放置在您的应用程序委派中下的didFinishLaunchingWithOptions

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

在viewDidLoad中大多数ViewController继承的视图控制器或视图控制器或基本视图控制器中,只需放置以下两行:

[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bar_background"]];
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparent_shadow"]];
确保透明_shadow@2x.png图像1x1或2x2是否透明,以及选项卡栏是否透明_background@2x.png是一个640x100的图像,因为底部栏的高度为50px


适用于iOS 9.3

在viewDidload上尝试此功能

override func viewDidLoad() {
        super.viewDidLoad()

        self.tabBar.setValue(true, forKey: "_hidesShadow")
}
这对我很管用

试试这个, **目标-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()

以下是苹果的指南

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


Swift 4

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

只需设置图像,它不会删除阴影线,您必须将其边框宽度设置为0。这是密码

[[UITabBar外观]设置阴影图像:[UIImage新建]]

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


[UITabBar外观].clipsToBounds=true

我通过以下方法获得了相同的外观。
1.将背景条淡色设置为与主父视图背景色相同。
二,


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

此代码适用于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()
}

如果需要从具有自定义字体的选项卡栏中删除iOS 13上的阴影线,则必须通过以下方式应用它:

if #available(iOS 13.0, *) {
   let appearance = UITabBarAppearance()
   appearance.stackedLayoutAppearance.normal.titleTextAttributes = ...
   appearance.stackedLayoutAppearance.selected.titleTextAttributes = ...
   appearance.shadowColor = .clear
   tabBar.standardAppearance = appearance
 }


我知道如何处理Uitabritem阴影,并且已经移除了它。我关心的是许多应用程序成功删除的UITabBar阴影(顶部的大线)。它成功了,谢谢:)(还有人想知道transparentShadow.png是1x1透明图像)谢谢伙计。。您的代码解决了许多尝试。。再次感谢。重要提示:“setShadowImage”的值在默认情况下被忽略,除非您还使用setBackgroundImage设置背景图像。所以你总是要把两者都设置好![来自苹果文档]别忘了:[[UITabBar外观]挫折背景图像:[[UIImage alloc]init]@罗杰:我不确定,如果你只需要去除阴影,有必要吗?是的。我必须这样做才能完全去除阴影,否则它仍会显示它。@Rogerfernandzguri,实际上它并没有显示阴影,但你看到的是选项卡栏的背景色。而不是“[[UITabBar外观]setBackgroundImage:[[UIImage alloc]init]];”,你也可以尝试设置背景颜色…在iOS 12上工作。但是在iOS13上不再工作了!有人试过吗?有一个新的
选项卡条.standardAppearance.shadowImage
但它根本不起作用…它是“uitabar”而不是UIToolBar。需要注意的是,这似乎没有文档记录。最好使用上面的方法,设置阴影和背景图像。您也可以在UI Abbar的Identity Inspector窗格的“用户定义的运行时属性”部分的Interface Builder中添加此选项。点击+添加一行并输入_hidesShadow键和值。这是访问私有API,因此可能会被拒绝,并可能在未来版本的iOS中中断。我使用Swift代码。它适用于2018年4月4日的iOS 11。iOS 10.X有一些更改,请遵循。仅使用
UITabBar.appearance().clipsToBounds=true
具有相同的效果。如果您在uitabaritem的文本上使用自定义字体,则会使用您的方法受到影响
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()
}
if #available(iOS 13.0, *) {
   let appearance = UITabBarAppearance()
   appearance.stackedLayoutAppearance.normal.titleTextAttributes = ...
   appearance.stackedLayoutAppearance.selected.titleTextAttributes = ...
   appearance.shadowColor = .clear
   tabBar.standardAppearance = appearance
 }