我尝试将阴影应用到默认选项卡栏。我从研究中找到了一些代码,但它不起作用。我想将此代码放在 AppDelegate 中以应用于所有 Controller 。
哪里错了?提前致谢
UITabBar.appearance().layer.shadowColor = UIColor.yellow.cgColor
UITabBar.appearance().layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
UITabBar.appearance().layer.shadowRadius = 15
UITabBar.appearance().layer.shadowOpacity = 1
UITabBar.appearance().layer.masksToBounds = false
最佳答案
试试这个
第 1 步 - 在 TabBarViewController 中创建一个函数 setupTabBar,如下所示
func setupTabBar() {
tabBar.layer.shadowColor = UIColor.yellow.cgColor
tabBar.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
tabBar.layer.shadowRadius = 15
tabBar.layer.shadowOpacity = 1
tabBar.layer.masksToBounds = false
}
第 2 步 - 从 viewDidLoad 调用
或者您可以创建自定义 TabBarViewController 类或按照您想要的方式创建它。
关于ios - AppDelegate 中的 Swift UITabbar Shadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53910559/