Ios 使用UIBezierPath:byRoundingCorners:Swift 2和Swift 3
我用这个代码使一个按钮的两个角变圆Ios 使用UIBezierPath:byRoundingCorners:Swift 2和Swift 3,ios,swift,uibezierpath,rounded-corners,Ios,Swift,Uibezierpath,Rounded Corners,我用这个代码使一个按钮的两个角变圆 let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: .TopLeft | .BottomLeft, cornerRadii: CGSizeMake(1.0, 1.0)) 它抛出一个错误: 二进制运算符“|”不能应用于两个UIRecentC
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: .TopLeft | .BottomLeft,
cornerRadii: CGSizeMake(1.0, 1.0))
它抛出一个错误:
二进制运算符“|”不能应用于两个UIRecentCorner操作数
如何在Swift 2.0中使用此方法?Swift 2:
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.TopLeft , .BottomLeft],
cornerRadii: CGSizeMake(1.0, 1.0))
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.topLeft ,.bottomLeft],
cornerRadii: CGSize(width:1.0, height:1.0))
Swift 3和Swift 4:
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.TopLeft , .BottomLeft],
cornerRadii: CGSizeMake(1.0, 1.0))
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.topLeft ,.bottomLeft],
cornerRadii: CGSize(width:1.0, height:1.0))
在这种情况下,swift 2.0中需要使两个角接合。F.例如:
let corners = UIRectCorner.TopLeft.union(UIRectCorner.BottomLeft)
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: corners,
cornerRadii: CGSizeMake(1.0, 1.0))
与Swift 2和Swift 3配合使用