Sunday, June 9, 2013

UINavigationBar shadowImage example in Objective C (iOS).


UINavigationBar shadowImage

The shadow image to be used for the navigation bar.

@property(nonatomic,retain) UIImage *shadowImage

Discussion of [UINavigationBar shadowImage]
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 shadowImage example.
if ([self.navigationController.navigationBar
respondsToSelector:@selector(shadowImage)]) {
self.navigationController.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
}

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

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

UINavigationBar shadowImage 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 shadowImage example article.