Custom IOS UITabbarController with hidden top gray line

人盡茶涼 提交于 2019-12-08 10:05:36

问题


I'd like to make a view with a unique color with uitabbar i.e I don't want to separate the view into the UITabbar and the rest, so I've created a custom UITabbar programmatically with custom color. The UITabbar and the "rest of the view" have the same color but there is a gray line on top of the UITabbar that separates the to parts. How can I hide that?

this is an example image, I want to delete that dark line: https://picasaweb.google.com/felixdl/20Giugno2012#5756005463317234882

SOLUTION

Thank you! this works perfectly! the line I've added is:

[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"myImage.jpg"]];

I've never used the "appearance" tag before


回答1:


If you're building for iOS 5, you can set the background as an image which would eliminate the grey line you're talking about.

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

This does require you to have an image which matches your programitically created color though.

In iOS4, you can override the drawRect function (which is significantly more complicated, but I'd be happy to answer if you're making a pre iOS 5 app)




回答2:


Try this, ** 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 document for 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).



来源:https://stackoverflow.com/questions/11104796/custom-ios-uitabbarcontroller-with-hidden-top-gray-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!