iOS可以使用渐变设置笔触线

时间:2015-10-05 16:20:03

标签: ios uiimage line gradient stroke

我有UIView画画。

我可以更改默认的笔划线

CGContextSetStrokeColorWithColor(context,UIColor.blackColor()。CGColor)

https://www.img.in.th/image/79xFhttp://catheria.com/wp-content/uploads/2015/10/StrokeLinear.png

下面是代码绘制半径渐变

UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
let ctx0 = UIGraphicsGetCurrentContext()
let colorSpace: CGColorSpaceRef = CGColorSpaceCreateDeviceRGB()!
let locations: [CGFloat] = [0.0, 0.4, 1.0]
let arrColor = [UIColor.blackColor().CGColor,UIColor.blackColor().CGColor, UIColor.clearColor().CGColor]
let _gradient: CGGradientRef = CGGradientCreateWithColors(colorSpace, arrColor, locations)!

CGContextDrawRadialGradient(ctx0, _gradient, CGPoint(x: size.width/2, y: size.height/2), CGFloat(0), CGPoint(x: size.width/2, y: size.height/2), CGFloat(60), CGGradientDrawingOptions())

let _img0 = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

0 个答案:

没有答案