JamesG
JamesG

Reputation: 1601

Top Rounded corners on node

I have a rectangle node:

let shape = SKShapeNode()
shape.path = UIBezierPath(roundedRect: CGRect(x: -128, y: -128, width: 256, height: 256), cornerRadius: 64).CGPath
shape.position = CGPoint(x: CGRectGetMidX(frame), y:    CGRectGetMidY(frame))
shape.fillColor = UIColor.redColor()
shape.strokeColor = UIColor.blueColor()
shape.lineWidth = 10
addChild(shape)

How do I add a border radius of 20 to the TopLeft and TopRight corners only?

Upvotes: 2

Views: 390

Answers (1)

John Estropia
John Estropia

Reputation: 17500

User this UIBezierPath initializer:

public convenience init(roundedRect rect: CGRect, byRoundingCorners corners: UIRectCorner, cornerRadii: CGSize)

and specify [.TopLeft, .TopRight] for the byRoundingCorners argument.

shape.path = UIBezierPath(
    roundedRect: CGRect(x: -128, y: -128, width: 256, height: 256),
    byRoundingCorners: [.TopLeft, .TopRight]
    cornerRadii: CGSize(width: 64, height: 64)).CGPath

Upvotes: 3

Related Questions