cashapelayer

How to draw a circle path with color gradient stroke

大憨熊 提交于 2019-11-26 14:32:23
问题 I want to draw a circle with color gradient stroke like the following picture, on both iOS and macOS: Is it possible to implement with CAShapeLayer or NSBezierPath / CGPath ? Or any other ways? 回答1: In macOS 10.14 and later (as well as in iOS 12 and later), you can create a CAGradientLayer with a type of .conic , and then mask it with a circular arc. For example, for macOS: class GradientArcView: NSView { var startColor: NSColor = .white { didSet { setNeedsDisplay(bounds) } } var endColor:

UIBezierPath Triangle with rounded edges

亡梦爱人 提交于 2019-11-26 11:50:19
问题 I have designed this code to generate a Bezier Path that is used as a path for a CAShapeLayer to mask a UIView (the view\'s height and width are variable) This code generates a triangle with sharp edges, but I would like to make it round cornered! I have spent a good 2 hours trying to work with addArcWithCenter... , lineCapStyle and lineJoinStyle etc but nothing seems to work for me. UIBezierPath *bezierPath = [UIBezierPath bezierPath]; CGPoint center = CGPointMake(rect.size.width / 2, 0);