Swift draw shadow to a uibezier path

前端 未结 3 1083
悲&欢浪女
悲&欢浪女 2021-02-06 16:01


I have a strange question. Even though I did read a lot of tutorials on how to do this, the final result only shows the bezier line, not any shadow whatsoever. My code is

3条回答
  •  别那么骄傲
    2021-02-06 16:34

    I take this example straight from my PaintCode-app. Hope this helps.

    //// General Declarations
    let context = UIGraphicsGetCurrentContext()
    
    
    //// Shadow Declarations
    let shadow = UIColor.blackColor()
    let shadowOffset = CGSizeMake(3.1, 3.1)
    let shadowBlurRadius: CGFloat = 5
    
    //// Bezier 2 Drawing
    var bezier2Path = UIBezierPath()
    bezier2Path.moveToPoint(CGPointMake(30.5, 90.5))
    bezier2Path.addLineToPoint(CGPointMake(115.5, 90.5))
    CGContextSaveGState(context)
    CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius,  (shadow as UIColor).CGColor)
    UIColor.blackColor().setStroke()
    bezier2Path.lineWidth = 1
    bezier2Path.stroke()
    CGContextRestoreGState(context)
    

提交回复
热议问题