Ios 如何为选定的选项卡栏提供渐变色?
我尝试将UITabBar子类化并应用渐变颜色,但我使用的代码将颜色添加到整个选项卡栏部分 使用的代码:Ios 如何为选定的选项卡栏提供渐变色?,ios,swift,xcode,uitabbarcontroller,uitabbaritem,Ios,Swift,Xcode,Uitabbarcontroller,Uitabbaritem,我尝试将UITabBar子类化并应用渐变颜色,但我使用的代码将颜色添加到整个选项卡栏部分 使用的代码: class TabViewController : UITabBarController { let gradientlayer = CAGradientLayer() override func viewDidLoad() { super.viewDidLoad() } func setUpSelectionIndic
class TabViewController : UITabBarController {
let gradientlayer = CAGradientLayer()
override func viewDidLoad() {
super.viewDidLoad()
}
func setUpSelectionIndicatorImage(withColors colors: [UIColor]) {
gradientlayer.frame = tabBar.bounds
gradientlayer.colors = [colors[0].cgColor, colors[1].cgColor]
gradientlayer.locations = [0, 1]
gradientlayer.startPoint = CGPoint(x: 1.0, y: 0.0)
gradientlayer.endPoint = CGPoint(x: 0.0, y: 0.0)
self.tabBar.layer.insertSublayer(gradientlayer, at: 0)
}
override func viewDidLayoutSubviews() {
super.viewWillLayoutSubviews()
let colors = [UIColor.IntroGradientColor1 , UIColor.IntroGradientColor2]
setUpSelectionIndicatorImage(withColors: colors)
}
}
你知道我怎样才能在所选的标签上实现这个蓝色渐变颜色吗,就像附件中的图片一样
创建两个资产,选中和未选中。然后将标签栏上的图片设置为选中时更改。这看起来真是天才和酷哈,我现在就要做了。我相信它会起作用,但还有其他办法吗!!要控制颜色以便我以后知道吗?创建一个自定义tabbar类,通过更改默认的tabbar控制器,您无法实现此屏幕。@asilturk any idea或reference hot来完成此操作@马哈茂德津吉一世也面临着同样的问题。您有任何解决方案吗?创建两个资产,选定和未选定。然后将标签栏上的图片设置为选中时更改。这看起来真是天才和酷哈,我现在就要做了。我相信它会起作用,但还有其他办法吗!!要控制颜色以便我以后知道吗?创建一个自定义tabbar类,通过更改默认的tabbar控制器,您无法实现此屏幕。@asilturk any idea或reference hot来完成此操作@马哈茂德津吉一世也面临着同样的问题。你有什么解决办法吗?