我试图让我的标签栏阴影看起来像在这张图片中看到的那样:
这样做的最佳方式是什么?我正在使用objective-c
感谢
答案 0 :(得分:12)
您可以使用以下代码为任何UI对象提供阴影
tabControl.layer.shadowOffset = CGSizeMake(0, 0);
tabControl.layer.shadowRadius = 2;
tabControl.layer.shadowColor = [UIColor blackColor].CGColor;
tabControl.layer.shadowOpacity = 0.3;
这里我举了tabControl对象的例子。
答案 1 :(得分:5)
对于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
答案 2 :(得分:4)
{{1}}
答案 3 :(得分:3)
我更喜欢使用专用标签栏方法。
// Set `backgroundImage` to be able to use `shadowImage`
tabBar.backgroundImage = UIImage.imageWithColor(.white)
tabBar.shadowImage = #imageLiteral(resourceName: "tab_bar_shadow") // 2x34pt works for me
答案 4 :(得分:2)
快捷键4:
使用此扩展程序
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!
}
}
使用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))
答案 5 :(得分:-1)
试试这个
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];