Давайте сосредоточимся на roundCorners(_ corners: radius:)
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let someNewMask = somethingNew(corners, radius: radius)
self.layer.mask = someNewMask
}
Вы делаете:
bigIconContentView.roundCorners([.topRight, .bottomLeft], radius: 30)
bigIconContentView.roundCorners([.topLeft], radius: 10)
Что в итоге делает это:
let someNewMask1 = somethingNew([.topRight, .bottomLeft], radius: 30)
bigIconContentView.mask = someNewMask1
let someNewMask2 = somethingNew([. topLeft], radius: 10)
bigIconContentView.mask = someNewMask2
Итак вы делаете:
bigIconContentView.mask = someNewMask1
bigIconContentView.mask = someNewMask2
Вы видите проблему? Вы переопределяете bigIconContentView
mask
новым каждый раз (последний вызывается).
Вы должны применять разные углы все вместе (в радиусе угла нет ничего сложного)
extension UIView {
func roundCornersRadii(topLeft: CGFloat = 0, topRight: CGFloat = 0, bottomLeft: CGFloat = 0, bottomRight: CGFloat = 0) {
let path = UIBezierPath()
path.move(to: CGPoint(x: topLeft, y: 0))
path.addLine(to: CGPoint(x: bounds.width - topRight, y: 0))
path.addArc(withCenter: CGPoint(x: bounds.width - topRight, y: topRight),
radius: topRight,
startAngle: -CGFloat.pi/2.0,
endAngle: 0,
clockwise: true)
path.addLine(to: CGPoint(x: bounds.width, y: bounds.width - bottomRight))
path.addArc(withCenter: CGPoint(x: bounds.width - bottomRight, y: bounds.height - bottomRight),
radius: bottomRight,
startAngle: 0,
endAngle: CGFloat.pi/2.0,
clockwise: true)
path.addLine(to: CGPoint(x: bottomRight, y: bounds.height))
path.addArc(withCenter: CGPoint(x: bottomLeft, y: bounds.height - bottomLeft),
radius: bottomLeft,
startAngle: CGFloat.pi/2.0,
endAngle: CGFloat.pi,
clockwise: true)
path.addLine(to: CGPoint(x: 0, y: topLeft))
path.addArc(withCenter: CGPoint(x: topLeft, y: topLeft),
radius: topLeft,
startAngle: CGFloat.pi,
endAngle: CGFloat.pi/2.0,
clockwise: true)
path.close()
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
Добавление образца теста:
let superView = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
let subview = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 200))
superView.backgroundColor = .red
subview.backgroundColor = .blue
subview.roundCornersRadii(topLeft: 20, topRight: 30, bottomLeft: 40, bottomRight: 50)
superView.addSubview(subview)
или в вашем случае:
let superView = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
let subview = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 200))
superView.backgroundColor = .red
subview.backgroundColor = .blue
subview.roundCornersRadii(topLeft: 20, topRight: 30, bottomLeft: 40, bottomRight: 50)
subview.roundCornersRadii(topLeft: 10, topRight: 30, bottomLeft: 30)
superView.addSubview(subview)