Ios 从TabBar中删除顶行
在iOS 10上,此代码无法删除选项卡栏阴影线:Ios 从TabBar中删除顶行,ios,ios10,tabbar,Ios,Ios10,Tabbar,在iOS 10上,此代码无法删除选项卡栏阴影线: [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]]; 有人知道,我该怎么做才能把它拿走 在ios9.3上,这两行代码将被删除,但ios10忽略setShadowImage命令。只需尝试吼叫ios10的代码即可:- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(N
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
有人知道,我该怎么做才能把它拿走
在
ios9.3
上,这两行代码将被删除,但ios10
忽略setShadowImage
命令。只需尝试吼叫ios10的代码即可:-
- (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
对于iOS 10,将tabbar样式更改为黑色就成功了
self.tabBarController.tabBar.shadowImage = UIImage()
self.tabBarController.tabBar.barStyle = .Black
我在ios 10上也有同样的问题。我修复了这个问题,只是更改了UITabBar的高度(默认为49)。检查如何更改高度。您应该同时执行以下两种方法:
[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
如果您创建自己的UITabBarController子类,则可以设置 viewDidLoad中的值如下所示 Swift 3
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.layer.borderWidth = 0
self.tabBar.clipsToBounds = true
}
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBarController.tabBar.standardAppearance copy];
appearance.shadowImage = nil;
appearance.shadowColor = nil;
self.tabBarController.tabBar.standardAppearance = appearance;
}
// remove top line
if #available(iOS 13.0, *) {
// ios 13.0 and above
let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
appearance.backgroundEffect = nil
// need to set background because it is black in standardAppearance
appearance.backgroundColor = .someColor
tabBar.standardAppearance = appearance
} else {
// below ios 13.0
let image = UIImage()
tabBar.shadowImage = image
tabBar.backgroundImage = image
// background
tabBar.backgroundColor = .someColor
}
这是tabbar的阴影图像(属性)。尝试以下解决方案并查看
试试这个,
**目标-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:(如果 使用默认背景图像时,将使用默认阴影图像 使用)
删除@iOS 13.0的背线
let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
tabBar.standardAppearance = appearance;
删除iOS 12.0及更早版本的背线
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
在iOS 14上测试
override func viewDidLoad() {
// Remove default border line
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
tabBar.backgroundColor = UIColor.white
}
适用于iOS 13
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.layer.borderWidth = 0
self.tabBar.clipsToBounds = true
}
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBarController.tabBar.standardAppearance copy];
appearance.shadowImage = nil;
appearance.shadowColor = nil;
self.tabBarController.tabBar.standardAppearance = appearance;
}
// remove top line
if #available(iOS 13.0, *) {
// ios 13.0 and above
let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
appearance.backgroundEffect = nil
// need to set background because it is black in standardAppearance
appearance.backgroundColor = .someColor
tabBar.standardAppearance = appearance
} else {
// below ios 13.0
let image = UIImage()
tabBar.shadowImage = image
tabBar.backgroundImage = image
// background
tabBar.backgroundColor = .someColor
}
我没有评论的名声,但要补充gnoix的回答,我有一个稍微不同的问题,我希望阴影和背景清晰,所以我在Swift中有
if #available(iOS 13.0, *) {
let appearance = tabBar.standardAppearance.copy()
appearance.configureWithTransparentBackground()
tabBar.standardAppearance = appearance
} else {
tabBar.backgroundColor = UIColor.clear
let image = UIImage(ciImage: CIImage(color: CIColor.clear)).af_imageAspectScaled(toFit: tabBar.bounds.size)
tabBar.backgroundImage = image
tabBar.shadowImage = image
}
这适用于我@iso13: AppDelegate.swift
UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().shadowImage = nil
或
或
您可以在FirstViewController中这样做。swift:
Swift 4.2
self.tabBarController!.tabBar.layer.borderWidth = 0.50
self.tabBarController!.tabBar.layer.borderColor = UIColor.clear.cgColor
self.tabBarController?.tabBar.clipsToBounds = true
只需根据需要更改边框颜色。从iOS 13.3开始的工作解决方案
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.layer.borderWidth = 0
self.tabBar.clipsToBounds = true
}
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBarController.tabBar.standardAppearance copy];
appearance.shadowImage = nil;
appearance.shadowColor = nil;
self.tabBarController.tabBar.standardAppearance = appearance;
}
// remove top line
if #available(iOS 13.0, *) {
// ios 13.0 and above
let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
appearance.backgroundEffect = nil
// need to set background because it is black in standardAppearance
appearance.backgroundColor = .someColor
tabBar.standardAppearance = appearance
} else {
// below ios 13.0
let image = UIImage()
tabBar.shadowImage = image
tabBar.backgroundImage = image
// background
tabBar.backgroundColor = .someColor
}
对我来说,tabBar外观的解决方案不起作用,因为在这种情况下它忽略了我的
tabBar.itemPositioning=.centered
适合我的是tabBar.barStyle=.black
不要忘了设置
tabBar.backgroundColor=.white
或您喜欢的任何其他颜色。如果您使用的是故事板,这是一种方法
在选项卡栏控制器上,选择“选项卡栏”
然后添加运行时属性“clipsToBounds”bool:
你能以图形的方式给我看吗?shadowImage文档的最后一行说,如果backgroundImage为零,则会忽略shadowImage,并应用默认的阴影。因此,请尝试删除setBackgroundImage,看看会发生什么。问题是我需要将image设置为tabBar background…@mitulmarsonia iOs 10模拟器的屏幕截图这段代码是我在iOs 10之前一直使用的。此代码适用于以前的iOs 10设备,但在iOs 10上不起作用。您可以尝试此演示吗?它适用于iOs 10:-谢谢您的示例代码。这段代码在iOs 10上运行,但我需要更改选项卡栏背景,当我更改背景时,将显示行。这个代码是相同的,只是我添加了一个背景图像,你可以看到阴影图像在iOs 10上显示,在iOs 9.3上工作正常,线条是隐藏的@Camacho我已经更新了我的答案,请现在查看您的问题已修复。感谢印度开发者社区,这不是您第一次帮助我解决有关stackoverflow的iOs问题,非常感谢!在iOS13上不再工作了!有人试过吗?有一个新的
tabBar.standardAppearance.shadowImage
但它根本不起作用…@SoftDesigner我也有同样的问题,你找到iOS 13的解决方案了吗?@YogendraPatel我正在使用一个自定义的阴影图像,我正在直接添加到选项卡栏:tabBar.addSubview(shadowImageView)
。它与标准1px行重叠。更新了iOS 13.0外观的答案,弄乱了未选择的选项卡颜色外观。configureWithTransparentBackground()
对我来说很有用,因为我在tabBar层上也有阴影。问题是只删除tabBar的顶线,而不是使tabBar背景透明。这个答案应该是正确的,因为标记为正确的答案会在应用外观时更改tabBar的颜色。