自定义IOS UITabbarController隐藏顶部的灰色线

我想使用uitabbar制作独特的颜色视图,即我不想将视图分离到UITabbar和其他视图中,所以我使用自定义颜色以编程方式创build了自定义UITabbar。 UITabbar和“视图的其余部分”具有相同的颜色,但在UITabbar的顶部有一条灰色的线条,用来分隔各部分。 我怎样才能隐藏呢?

这是一个示例图像,我想删除那条黑线: https : //picasaweb.google.com/felixdl/20Giugno2012#5756005463317234882

谢谢! 这完美的作品! 我添加的行是:

[UITabBar外观] setBackgroundImage:[UIImage imageNamed:@“myImage.jpg”]];

我从来没有使用过“外观”标签

如果您正在构buildiOS 5,则可以将背景设置为可以消除您所说的灰线的图像。

[uiTabBarController setBackgroundImage:[UIImage imageNames:@"my_background.png"]]; 

这确实需要你有一个图像,它符合你的程序创build的颜色。

在iOS4中,您可以重写drawRect函数(这非常复杂,但如果您正在制作iOS 5以前版本的应用程序,我很乐意回答)

试试这个,** 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的 apple文件。

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

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