问题
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