method 1:
//The edges of the picture are blurred
let colorLayer =CAGradientLayer()
colorLayer.frame =circleImageIcon.frame
colorLayer.position =circleImageIcon.center
//Set gradient color and transparency
colorLayer.colors = [UIColor(red:250 /255.0, green:250 /255.0, blue:250 /255.0, alpha:0.1).CGColor,UIColor(red:250 /255.0, green:250 /255.0, blue:250 /255.0, alpha:0.5).CGColor,UIColor(red:250 /255.0, green:250 /255.0, blue:250 /255.0, alpha:1.0).CGColor]
//Color dividing line
colorLayer.locations = [0.5,0.75]
//Orange starting point
colorLayer.startPoint =CGPointMake(0.5,0)
colorLayer.endPoint =CGPointMake(1,0)
circleImageIcon.layer.insertSublayer(colorLayer, atIndex:0)
Method 2
Create a new class that inherits from UIVIew and overrides the drawRect method.
//Get context
let context =UIGraphicsGetCurrentContext()
// let gradient: CGGradientRef
let colorSpace =CGColorSpaceCreateDeviceRGB()
//Color Gradient Component,A set of four numbers corresponding respectively< a i=4>rgbTransparency
let componets:[CGFloat] = [220.0,220.0, 220.0,0.1,220.0,220.0,220.0, 1]
//fixed position
let locations:[CGFloat] = [0,1]
let gradient =CGGradientCreateWithColorComponents(colorSpace, componets, locations,2)!
//绘线性渐变
CGContextDrawLinearGradient(context, gradient,CGPointMake(0, rect.size.height),CGPointMake(rect.size.width, rect.size.height),CGGradientDrawingOptions.DrawsAfterEndLocation)