Reputation: 5066
I can't remove the shadow from my UINavigationBar for some reason on iOS6. Why isn't this working? I've tried the following:
if ([[UINavigationBar appearance]respondsToSelector:@selector(setShadowImage:)]){
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
}
if ([[UINavigationBar class]respondsToSelector:@selector(setShadowImage:)]){
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
}
Upvotes: 4
Views: 2548
Reputation: 76
Mike Pollard has it right.
To remove the shadow underneath the UINavigationBar
on iOS 6, you need to set a custom background image in addition to setting the shadow image to a blank UIImage
.
CustomViewController.m
- (void)viewDidLoad
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Background"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
In the above example, "Background" would be a PNG image in your project.
Upvotes: 1
Reputation: 10195
This had me stumped for a while until I read the docs!
NOTE:
For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics:
method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.
Upvotes: 2
Reputation: 6393
You have to do the work on a NavigationBar instance...
if ([navigationBarInstance respondsToSelector:@selector(setShadowImage:)]){
[navigationBarInstance setShadowImage:[[UIImage alloc] init]];
}
Edit: If you for some reason really need to perform the check on the class. This will work:
if ([UINavigationBar instancesRespondToSelector:@selector(setShadowImage:)]) {
}
Upvotes: 3