我通过storyboard构建了选项卡栏,并通过UITabBar.appearance().barTintColor = Color
在应用程序委托中定制了颜色。
我有一个渐变方法,如下:
func setGradientBackground(colorOne: UIColor, colorTwo: UIColor) {
let gradientlayer = CAGradientLayer()
gradientlayer.frame = 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)
layer.insertSublayer(gradientlayer, at: 0)
}
我该如何将其应用于我的选项卡栏的背景?