On OSX, how do I gradient fill a path stroke?

前端 未结 3 462
遇见更好的自我
遇见更好的自我 2020-12-04 18:32

Using the plethora of drawing functions in Cocoa or Quartz it\'s rather easy to draw paths, and fill them using a gradient. I can\'t seem to find an acceptable way however,

3条回答
  •  醉酒成梦
    2020-12-04 19:36

    If you convert the NSBezierPath to a CGPath, you can use the CGContextReplacePathWithStrokedPath() method to retrieve a path that is the outline of the stroked path. Graham Cox's excellent GCDrawKit has a -strokedPath category method on NSBezierPath that will do this for you without needing to drop down to Core Graphics.

    Once you have the outlined path, you can fill that path with an NSGradient.

提交回复
热议问题