1.代码如下,仅供参考
override func draw(_ rect: CGRect) {
//绘制小三角形
guard let context = UIGraphicsGetCurrentContext() else {
return
}
let drawingRect = bounds
let path = CGMutablePath()
//设立设置的三角形在中间,具体位置可以自定
path.move(to: CGPoint(x: drawingRect.width/4.0 * 3.0, y: 0))
path.addLine(to: CGPoint(x: drawingRect.width/4.0 * 3.0 - 8, y: 8))
path.addLine(to: CGPoint(x: drawingRect.width/4.0 * 3.0 + 8, y: 8))
context.setFillColor(UIColor.navBgColor.cgColor)
context.addPath(path)
context.fillPath()
}
2.制作一个不规范的圆角矩形
截屏2022-02-15 上午11.38.57.png
let path2 = CGMutablePath()
path2.addRoundedRect(in: CGRect.init(x: 100, y: 100, width: 100, height: 100), cornerWidth: 25.0, cornerHeight:50)
context.setFillColor(UIColor.green.cgColor)
context.addPath(path2)
context.fillPath()
网友评论