[英]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.