我知道如何通过设置类似于以下内容的拐角半径来对所有四个角进行圆角处理:
func rounded() {
self.layer.cornerRadius = self.frame.size.height / 2
}
但不确定如何仅将2个圆角倒圆。任何帮助表示赞赏。
答案 0 :(得分:0)
您可以尝试
extension UIView {
func roundedLeftTopBottom(){
self.clipsToBounds = true
let maskPath1 = UIBezierPath(roundedRect: bounds,
byRoundingCorners: [.topLeft , .bottomLeft],
cornerRadii: CGSize(width:self.frame.size.height / 2, height:self.frame.size.height / 2))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = bounds
maskLayer1.path = maskPath1.cgPath
layer.mask = maskLayer1
}
// or
func round () {
self.layer.cornerRadius = self.frame.size.height / 2
self.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner]
}
}
如果视图位于vc内,请确保在layoutSubviews
或viewDidLayoutSubviews
内调用其中任何一个,以使帧尺寸正确