下面是实现半圆的实现方法。
调用方法:
实现代码如下:
```
/**半圆**/
struct HalfCircleView: View {
/**
cenetrType 半圆位置
0 :leftCenter
1 :rightCenter
2 :topCenter
3 :bottomCenter
**/
varcenetrType:Int=0
varfillColor:Color=Color(hex:"#E9F0ED")
varbody:someView{
GeometryReader{ geometryin
Path{ pathin
varcenetr1 =CGPoint(x:0,y: geometry.size.height/2)
letradius =min(geometry.size.width, geometry.size.height) /2
ifcenetrType==0{
cenetr1 =CGPoint(x:0,y: geometry.size.height/2)
path.addArc(center: cenetr1,radius: radius,startAngle: .degrees(-90),endAngle: .degrees(90),clockwise:false)
}
ifcenetrType==1{
cenetr1 =CGPoint(x: geometry.size.width,y: geometry.size.height/2)
path.addArc(center: cenetr1,radius: radius,startAngle: .degrees(90),endAngle: .degrees(-90),clockwise:false)
}
ifcenetrType==2{
cenetr1 =CGPoint(x: geometry.size.width/2,y:0)
path.addArc(center: cenetr1,radius: radius,startAngle: .degrees(0),endAngle: .degrees(180),clockwise:false)
}
ifcenetrType==3{
cenetr1 =CGPoint(x: geometry.size.width/2,y: geometry.size.height)
path.addArc(center: cenetr1,radius: radius,startAngle: .degrees(180),endAngle: .degrees(0),clockwise:false)
}
}
.fill(fillColor)// 设置透明度
}
}
}
```