func createGradientLayer(color : UIColor, width : CGFloat, height : CGFloat) -> UIImageView{
let layer : CAGradientLayer = CAGradientLayer ()
let gradientColors: [CGColor] = [color.CGColor, UIColor.whiteColor().CGColor]
let gradientLocations: [CGFloat] = [0.0, 1.0]
layer.colors = gradientColors
layer.locations = gradientLocations
layer.startPoint = CGPointMake(0, 0)
layer.endPoint = CGPointMake(1, 0)
layer.frame = CGRectMake(0, 0, width, height)
let imageView : UIImageView = UIImageView(
imageView.layer.addSublayer(layer)
return imageView
}
Swift 返回一个渐变的 UIImageView
最新推荐文章于 2018-11-13 10:54:36 发布