UICollectionView

时间:2016-03-20 22:16:30

标签: ios swift collectionview

我在没有UICollecionView的viewControllers上设置了一些渐变颜色代码并且它有效。当我在UICollectionViewController上尝试渐变代码时,渐变不起作用。有谁知道如何向UICollectionView添加渐变? (collectionView在普通的viewController中)

渐变代码:

let topColor = UIColor(red: (191/255.0), green: (143/255.0), blue: (248/255.0), alpha: 1)
let bottomColor = UIColor(red: (131/255.0), green: (82/255.0), blue: (182/255.0), alpha: 1)

let gradientColors: [CGColor] = [topColor.CGColor, bottomColor.CGColor]
let gradientLoactions: [Float] = [0.0, 1.0]
let gradientLayer: CAGradientLayer = CAGradientLayer()
gradientLayer.colors = gradientColors
gradientLayer.locations = gradientLoactions
gradientLayer.frame = self.view.bounds
self.view.layer.insertSublayer(gradientLayer, atIndex: 0)

0 个答案:

没有答案