如何在Swift 4的标签栏图标上应用渐变?

时间:2019-05-06 17:46:14

标签: swift user-interface uitabbarcontroller uitabbar

我正在尝试向选项卡栏中的图标添加渐变,目前,我在此处找到了一种使选项栏渐变的方法,我认为这很接近,但是我该如何使用它标签图标?与此https://imgur.com/a/NmKLkys

相似
class GradientTabBarController: UITabBarController {

    let gradientlayer = CAGradientLayer()

    override func viewDidLoad() {
        super.viewDidLoad()
        setGradientBackground(colorOne: .yellow, colorTwo: .red)
    }

    func setGradientBackground(colorOne: UIColor, colorTwo: UIColor)  {
        gradientlayer.frame = tabBar.bounds
        gradientlayer.colors = [colorOne.cgColor, colorTwo.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)
    }
}

0 个答案:

没有答案