Swift AppDelegate 中的 UITabbar 阴影
Swift UITabbar Shadow in AppDelegate
我尝试将阴影应用于默认标签栏。我从研究中找到了一些代码,但它不起作用。我想将此代码放入 AppDelegate 以应用于所有控制器。
错在哪里?提前致谢
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
使用任何工具创建阴影颜色的图像,或者您可以通过编程方式进行。
之后在 AppDelegate 中使用下面的代码
//Set Shadow Color
UITabBar.appearance().shadowImage = YOURSHADOWIMAGE
试试这个
第 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 class 或按照您的需要创建它。
尝试 self.tabBar.layer 而不是 UITabBar.appearance()
我尝试将阴影应用于默认标签栏。我从研究中找到了一些代码,但它不起作用。我想将此代码放入 AppDelegate 以应用于所有控制器。
错在哪里?提前致谢
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
使用任何工具创建阴影颜色的图像,或者您可以通过编程方式进行。
之后在 AppDelegate 中使用下面的代码
//Set Shadow Color
UITabBar.appearance().shadowImage = YOURSHADOWIMAGE
试试这个
第 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 class 或按照您的需要创建它。
尝试 self.tabBar.layer 而不是 UITabBar.appearance()