我想为Swift -3中的视图设置不同的角半径,我能够将每个角的半径设置为相同的值,如下面的帖子中提到的那样,how to set cornerRadius for only top-left and top-right corner of a UIView?
有没有办法按以下格式设置转角半径?
半径左上:18
半径右上:18
半径右下:3
半径左下:18
您可以将默认的layer.cornerRadius设置为最小值,然后将图层蒙版的边框设置为更大的值.
let demoView = UIView(frame: CGRect(x: 100,y: 200,width: 100,height: 100)) demoView.backgroundColor = UIColor.red demoView.layer.cornerRadius = 3.0 let maskPath = UIBezierPath(roundedRect: demoView.bounds,byRoundingCorners: [.topLeft,.topRight,.bottomLeft],cornerRadii: CGSize(width: 18.0,height: 0.0)) let maskLayer = CAShapeLayer() maskLayer.path = maskPath.cgPath demoView.layer.mask = maskLayer view.addSubview(demoView)