快速連結

2023年9月19日

[Swift5]只想要UIView某一邊使用圓弧


 let cornerPath = UIBezierPath(roundedRect: myView.bounds, byRoundingCorners: [.bottomLeft, .topLeft], cornerRadii:  CGSize(width: 8, height:  8))
 let maskLayer = CAShapeLayer()
 maskLayer.path = cornerPath.cgPath
 myView.layer.mask = maskLayer
UIBezierPath參數內容:
roundedRect:要做mask的UIView的bounds。
byRoundingCorners:要做圓弧角的地方,有左上、左下、右上、右下,也有全部都要的allCorners可以用。
cornerRadii:圓角大小,CGSize物件,寬度=水平弧度,高度=垂直弧度。詳細可以看這篇:Why is cornerRadii parameter of CGSize type in...