iOS - UIView设置四个角不同的弧度

let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
view.backgroundColor = UIColor.red

let path1 = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 100, height: 100), byRoundingCorners: .topLeft, cornerRadii: CGSize(width: 45, height: 10))
let path2 = UIBezierPath(roundedRect: CGRect(x: 100, y: 0, width: 100, height: 100), byRoundingCorners: .topRight, cornerRadii: CGSize(width: 20, height: 20))
let path3 = UIBezierPath(roundedRect: CGRect(x: 0, y: 100, width: 100, height: 100), byRoundingCorners: .bottomLeft, cornerRadii: CGSize(width: 30, height: 30))
let path4 = UIBezierPath(roundedRect: CGRect(x: 100, y: 100, width: 100, height: 100), byRoundingCorners: .bottomRight, cornerRadii: CGSize(width: 40, height: 40))

path1.append(path2)
path1.append(path3)
path1.append(path4)

let shape = CAShapeLayer()
shape.path = path1.cgPath
view.layer.mask = shape
效果图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容