UIBezierPath Init () does not expect RoundingCorners parameter

You cannot use the typical init for UIBezierPath, which contains the parameter parameter RoundingCorners:

var maskPath = UIBezierPath(roundedRect: headerView.bounds, byRoundingCorners: (UIRectCorner.TopLeft | UIRectCorner.TopRight), cornerRadii: 5.0) 

Gives "Extra argument" byRoundingCorners when called

Is this a Swift bug?

+6
source share
1 answer

This is a Swift error, as the error message is quite misleading. The real mistake is that the cornerRadii parameter is of type CGSize , but you are passing a floating point number (compare Why the cornerRadii parameter of type CGSize is [UIBezierPath bezierPathWithRoundedRect: byRoundingCorners: cornerRadii:]? ).

This should work (Swift 1.2):

 var maskPath = UIBezierPath(roundedRect: headerView.bounds, byRoundingCorners: .TopLeft | .TopRight, cornerRadii: CGSize(width: 5.0, height: 5.0)) 

Note that in Swift 2, the byRoundingCorners argument type has been changed to OptionSetType :

 var maskPath = UIBezierPath(roundedRect: headerView.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSize(width: 5.0, height: 5.0)) 
+20
source

Source: https://habr.com/ru/post/972678/


All Articles