Sunday, June 9, 2013

UINavigationBar setShadowImage example in Objective C (iOS).


UINavigationBar setShadowImage

The shadow image to be used for the navigation bar.

@property(nonatomic,retain) UIImage *shadowImage

Discussion of [UINavigationBar setShadowImage]
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. 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.

UINavigationBar setShadowImage example.
if ([self.navigationController.navigationBar
respondsToSelector:@selector(shadowImage)]) {
self.navigationController.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
}

Example of [UINavigationBar setShadowImage].
You have to do the work on a NavigationBar instance...

if ([navigationBarInstance respondsToSelector:@selector(setShadowImage:)]){
    [navigationBarInstance setShadowImage:[[UIImage alloc] init]];
}

UINavigationBar setShadowImage example.
iOS6 has added a drop shadow to the Navigation Bar. So the masking code that I was using with iOS5 still works fine - I just need to add

if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)])
{
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
to get rid of the drop shadow.

End of UINavigationBar setShadowImage example article.