导入SwiftUI
struct DashboardAcftView:查看{
这是状态属性存储并保存到持久性容器的地方。
@ObservedObject public var updateMaleBodyCompView = UpdateMaleBodyCompView()
这是获取请求。
@FetchRequest(entity: MaleBodyComp.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \MaleBodyComp.createdAt, ascending: false)]) var maleBodyComp: FetchedResults<MaleBodyComp>
这是将授权BF Double和身体脂肪Double并返回颜色的函数。
func colorCategory(bf: Double, authBf: Double) -> Color {
let goColor: Color = Color.green
let noGoColor: Color = Color.red
let bf = updateMaleBodyCompView.bodyFat
let authBf = updateMaleBodyCompView.authBodyFat
if Int(authBf) < Int(bf) {
return noGoColor
}
return goColor
}
var body: some View {
Text("ABCP Snapshot").font(.headline)
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .bottom, spacing: CGFloat(0)) {
ForEach(self.maleBodyComp, id: \.self) { bf in
此处是环形视图更新和动画的地方。它仅在“ if”语句之外更新返回范围。因此,在这种情况下为Color.green。
RingViewAbcp(precent: 23, radius: 22, **color: self.colorCategory(bf: bf.bodyFat, authBf: bf.authBodyFat)** , width: 7, ringAuthBodyFat: Int(bf.authBodyFat), ringBodyFat: Int(bf.bodyFat), recordDate: bf.createdAt ?? Date(), recordLabel: "ABCP Date", animationDuration: 1.5)
}
}
}
}
}
}