[英]How to make sub view to be round corner as super view in iOS?
在添加子視圖時,請將masksToBounds
設置為true
,
subView.masksToBounds = true
嘗試也將cornerRadius
添加到子視圖。
subview.layer.masksToBounds = false
subview.layer.cornerRadius = 10
更新
通過使用UIBezierPath
我們可以將圓度添加到所需的任何角。
subview.roundCorners([.topLeft, .topRight, .bottomRight], radius: 6)
延期
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.