Swift 返回一个渐变的 UIImageView

来源:互联网 发布:js e.currenttarget 编辑:程序博客网 时间:2024/06/05 02:15

C2FAB957-6E0E-45E9-B6C0-8B807770B828.png

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}