I want to replace a default border in UINavigationBar with shadow. Is there any way to achieve this? I have tried using the same approach as with adding shadow to UIView but it increases a height of my NavigationBar. 
            Asked
            
        
        
            Active
            
        
            Viewed 1.8k times
        
    14
            
            
         
    
    
        Anbu.Karthik
        
- 82,064
- 23
- 174
- 143
 
    
    
        alexxjk
        
- 1,681
- 5
- 18
- 30
1 Answers
36
            try this
self.navigationController.navigationBar.layer.shadowColor = UIColor.blackColor().CGColor
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(2.0, 2.0)
self.navigationController.navigationBar.layer.shadowRadius = 4.0
self.navigationController.navigationBar.layer.shadowOpacity = 1.0
Swift 3
 override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.layer.shadowColor = UIColor.black.cgColor
    self.navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
    self.navigationController?.navigationBar.layer.shadowRadius = 4.0
    self.navigationController?.navigationBar.layer.shadowOpacity = 1.0
    self.navigationController?.navigationBar.layer.masksToBounds = false
 }
output as
 
    
    
        Anbu.Karthik
        
- 82,064
- 23
- 174
- 143
- 
                    Thank you @Abnu.Karthik! It has almost solved my problem but there is still a small issue. The border of color of black is still there.. Can I hide it somehow? – alexxjk Aug 05 '16 at 08:30
- 
                    see rthis once http://stackoverflow.com/questions/19226965/how-to-hide-ios7-uinavigationbar-1px-bottom-line – Anbu.Karthik Aug 05 '16 at 08:35
