似乎不能使用包含参数byRoundingCorners参数的UIBezierPath的典型init:
var maskPath = UIBezierPath(roundedRect: headerView.bounds, byRoundingCorners: (UIRectCorner.TopLeft | UIRectCorner.TopRight), cornerRadii: 5.0)
给出错误"额外参数' byRoundingCorners in call"
这是一个Swift错误吗?
答案 0 :(得分:20)
这是一个Swift错误,因为错误消息非常具有误导性。
真正的错误是cornerRadii
参数的类型为CGSize
,
但是你传递的是一个浮点数(比较Why is cornerRadii parameter of CGSize type in -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]?)。
这应该有效(Swift 1.2):
var maskPath = UIBezierPath(roundedRect: headerView.bounds,
byRoundingCorners: .TopLeft | .TopRight,
cornerRadii: CGSize(width: 5.0, height: 5.0))
请注意,在Swift 2中,byRoundingCorners参数的类型已更改为OptionSetType
:
var maskPath = UIBezierPath(roundedRect: headerView.bounds,
byRoundingCorners: [.TopLeft, .TopRight],
cornerRadii: CGSize(width: 5.0, height: 5.0))