急转弯半径问题
let path = UIBezierPath(roundedRect:username.bounds, byRoundingCorners:[.TopRight, .BottomLeft], cornerRadii: CGSizeMake(20, 20))
let maskLayer = CAShapeLayer()
maskLayer.path = path.CGPath
username.layer.mask = maskLayer
Output
I Want
最佳答案
如果将要赋予角点的视图子类化,则可以这样做:
override func layoutSubviews() {
super.layoutSubviews()
maskLayer.frame = self.bounds
maskLayer.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.topLeft.union(.topRight), cornerRadii: CGSize(width: 25, height: 25)).cgPath
self.layer.mask = maskLayer
}
关于swift - swift cornerradius仅左下和右上?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38059065/