I have simple project in swiftUI, everythings is work, but
HStack for Rectangle() as I mention below, do not alignment the Rectangle and text at the same line, and idea will be appreciated.
struct App: View {
var body: some View {
GeometryReader{g in
ZStack {
ForEach(0..data.count) { i in
DrawShape(center: CGPoint(x:g.frame(in: .global).width/2, y: g.frame(in: .global).height/2), index: i)
}
}
}
.frame(height: 200)
.clipShape(Circle())
.shadow(radius: 10)
VStack{
ForEach(data) { i in
HStack {
Text(i.name)
.frame(width:100)
.padding()
GeometryReader { g in
HStack{
Spacer(minLength: 0)
Rectangle()
.fill(i.color)
.frame(width: self.getWidth(width: g.frame(in: .global).width, value: i.percent) ,height: 10)
Text(String(format: "\(i.percent)", "%.0f"))
.fontWeight(.bold)
.padding(.leading,10)
.frame(width:80)
Spacer()
}.frame(width: 240, height: 30)
}
}
}
.padding()
Spacer()
}
}
func getWidth(width: CGFloat, value: CGFloat) - CGFloat {
let temp = value / 100
return temp * width
}
}
3
0
3.4k