title: How to create UINavigationBar drop shadow
body: <p>Would like to know create drop shadow for UINavigationbar. I tried to create custom navigation bar background with drop shadow, but the drop shadow cover the background view. </p>
  
  <pre><code>@implementation UINavigationBar (CustomImage)
  - (void)drawRect:(CGRect)rect {
     UIImage *image = [[UIImage imageNamed:@"titleBar.png"] retain];;
     [image drawInRect:rect];
     [image release];
  }
  
  - (CGSize)sizeThatFits:(CGSize)size {
     CGSize newSize = CGSizeMake(320,50);
     return newSize;
  }
  @end
  
  I also tried on following solution: http://www.travisboudreaux.com/adding-a-drop-shadow-to-a-uinavigationbar: 
  
  @interface UINavigationBar (dropshadow)
  
  -(void) applyDefaultStyle;
  
  @end
  
  @implementation UINavigationBar (dropshadow)
  
  -(void)willMoveToWindow:(UIWindow *)newWindow{
     [self applyDefaultStyle];
  }
  
  - (void)applyDefaultStyle {
    // add the drop shadow
    self.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.layer.shadowOffset = CGSizeMake(0.0, 3.0);
    self.layer.shadowOpacity = 0.25;
  }
  @end
  </code></pre>
  
  <p>It shows drop shadow for my navigationbar button, but no the navigation bar itself. </p>
  
  <p><strong>Final Solution:</strong>
  Here's how I create drop shadow for UINavigationBar. Big thanks for MusiGenesis for pointing out the missing link of my code:</p>
  
  <pre><code>#import &lt;QuartzCore/QuartzCore.h&gt;
  
  @interface UINavigationBar (CustomImage)
  
  -(void) applyDefaultStyle;
  
  @end
  
  //Override For Custom Navigation Bar
  @implementation UINavigationBar (CustomImage)
  - (void)drawRect:(CGRect)rect {
      UIImage *image = [UIImage imageNamed: @"titleBar.png"];
      [image drawInRect:CGRectMake(0, 0, 320, 44)];   
  }
  
  -(void)willMoveToWindow:(UIWindow *)newWindow{
      [super willMoveToWindow:newWindow];
      [self applyDefaultStyle];
  }
  
  - (void)applyDefaultStyle {
      // add the drop shadow
      self.layer.shadowColor = [[UIColor blackColor] CGColor];
      self.layer.shadowOffset = CGSizeMake(0.0, 3);
      self.layer.shadowOpacity = 0.25;
      self.layer.masksToBounds = NO;
      self.layer.shouldRasterize = YES;
  }
  
  @end
  </code></pre>
  
  <p>** Remember to import quartzcore or it will throw error.</p>