Swift 返回一個漸變的 UIImageView

Brocadecarp發表於2018-04-23

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
}
複製程式碼

相關文章