iOS 7中,苹果在tabBar上面添加了一条微小的线条,旨在作为tabBar和UI之间的阴影或淡出效果。
由于我正在使用自定义的tabBar,这条线让人感到非常烦人。如何去掉它?请告诉我这是可能的,否则我需要重新设计我的整个应用程序....
/问候
*编辑
通过以下代码解决了我的问题:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
iOS 7中,苹果在tabBar上面添加了一条微小的线条,旨在作为tabBar和UI之间的阴影或淡出效果。
由于我正在使用自定义的tabBar,这条线让人感到非常烦人。如何去掉它?请告诉我这是可能的,否则我需要重新设计我的整个应用程序....
/问候
*编辑
通过以下代码解决了我的问题:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar_bg.png"];
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
setShadowImage
方法,它会占据Tab Bar Controller上方的一些空间。最好使用[[UITabBar appearance] setShadowImage:[[UIImage alloc] init];
来提供一个空的透明UIImage
。 - Raptor对我来说这些代码运行得相当好(我没有为选项卡栏设置背景图像):
[tab_main.tabBar setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
我使用这些代码也可以添加一个框架:
UIColor* color_green = UIColorFromRGB(0x348e5b);
tab_main.tabBar.layer.borderWidth = 0.50;
tab_main.tabBar.layer.borderColor = color_green.CGColor;
[[UITabBar appearance] setTintColor:color_green];
希望这有所帮助。Swift
简单易行的解决方案:
在你的自定义选项卡栏类中添加以下代码即可隐藏水平阴影线。
self.tabBar.setValue(true, forKey: "_hidesShadow")
Objective C
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
self.tabBarController = [[UITabBarController alloc] init];
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"YOURIMAGE.png"]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
tabBar
,但你在其上初始化了UITabBarController
。 - RaptortabBarController
,以避免混淆。 - Raptor试试这个, ** 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()
这里是苹果文档shadowImage。
@available(iOS 6.0, *)
open var shadowImage: UIImage?
这对我有用
UIImage* tabBarBackground = [UIImage new];
if(!OSVersionIsAtLeastiOS7())
{
tabBarBackground = [UIImage imageNamed:@"whitebg"];
}
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
AppDelegate.m
的didFinishLaunchingWithOptions:
方法中。if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
我在UITabBar
API中没有找到任何影响分隔符的内容,但是如果分隔符在UITabBar中(一个UIView子类),我希望你可以在其上方插入一个新的一像素高的UIView。你需要截取想要显示的图像部分,并在新的视图中绘制它。而且我不确定UITabBar是否会阻止添加子视图或阻止子视图处于顶层。但这是我会开始的地方。
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabtarsprnt"]]; //your custom image
[self.tabBarController.tabBar setClipsToBounds:YES];
这段代码也解决了我的问题
[_tabBar setClipsToBounds:TRUE];
- holex