Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何为选定的选项卡栏提供渐变色?_Ios_Swift_Xcode_Uitabbarcontroller_Uitabbaritem - Fatal编程技术网

Ios 如何为选定的选项卡栏提供渐变色?

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

我尝试将UITabBar子类化并应用渐变颜色,但我使用的代码将颜色添加到整个选项卡栏部分

使用的代码:

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来完成此操作@马哈茂德津吉一世也面临着同样的问题。你有什么解决办法吗?