美文网首页
iOS - UIView设置四个角不同的弧度

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

作者: 随风踏叶 | 来源:发表于2018-08-27 15:50 被阅读63次
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
效果图

相关文章

网友评论

      本文标题:iOS - UIView设置四个角不同的弧度

      本文链接:https://www.haomeiwen.com/subject/hectwftx.html