IOS - Getting the desired shadow above the UITabBar

I'm trying to make the shadow on the tab bar look like the one shown in this image:

O1zKe.png

What is the best way to do this? I am using objective-c
Thanks

+10
source share
6 answers

You can give a shadow using the following code for any user interface object

tabControl.layer.shadowOffset = CGSizeMake(0, 0); tabControl.layer.shadowRadius = 2; tabControl.layer.shadowColor = [UIColor blackColor].CGColor; tabControl.layer.shadowOpacity = 0.3; 

Here I gave an example for your tabControl object.

+11
source

Swift 4:

 tabBar.layer.shadowOffset = CGSize(width: 0, height: 0) tabBar.layer.shadowRadius = 2 tabBar.layer.shadowColor = UIColor.black.cgColor tabBar.layer.shadowOpacity = 0.3 
+4
source

For Swift 4:

 self.tabBarController?.tabBar.layer.shadowColor = UIColor.black.cgColor self.tabBarController?.tabBar.layer.shadowOffset = CGSize(width: 0.0, height: 1.0) self.tabBarController?.tabBar.layer.shadowRadius = 5 self.tabBarController?.tabBar.layer.shadowOpacity = 1 self.tabBarController?.tabBar.layer.masksToBounds = false 
+4
source

I would prefer to use the special methods of the tab bar.

 // Set `backgroundImage` to be able to use `shadowImage` tabBar.backgroundImage = UIImage.imageWithColor(.white) tabBar.shadowImage = #imageLiteral(resourceName: "tab_bar_shadow") // 2x34pt works for me 
+3
source

Swift 4:

Use this extension

 extension UIImage { class func colorForNavBar(color: UIColor) -> UIImage { //let rect = CGRectMake(0.0, 0.0, 1.0, 1.0) let rect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: 1.0, height: 1.0)) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() context!.setFillColor(color.cgColor) context!.fill(rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! } } 

Set shadow color using RGB

 //Set BackgroundColor UITabBar.appearance().backgroundImage = UIImage.colorForNavBar(color: .white) //Set Shadow Color UITabBar.appearance().shadowImage = UIImage.colorForNavBar(color: UIColor.init(red: 120/255.0, green: 120/255.0, blue: 120/255.0, alpha: 1.0)) 
+1
source

Try this one

  [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]]; 
-1
source

All Articles