【发布时间】:2020-08-28 07:15:09
【问题描述】:
嘿,有人知道如何在 swiftUI 中创建矩形进度条吗?
这样的? https://i.stack.imgur.com/CMwB3.gif
我试过这个:
struct ProgressBar: View
{
@State var degress = 0.0
@Binding var shouldLoad: Bool
var body: some View
{
RoundedRectangle(cornerRadius: cornerRadiusValue)
.trim(from: 0.0, to: CGFloat(degress))
.stroke(Color.Scheme.main, lineWidth: 2.0)
.frame(width: 300, height: 40, alignment: .center)
.onAppear(perform: shouldLoad == true ? {self.start()} : {})
}
func start()
{
Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true)
{
timer in
withAnimation
{
self.degress += 0.3
}
}
}
}
【问题讨论】:
-
展示你自己的尝试并参考这个stackoverflow.com/help/how-to-ask,然后有人可以帮助你。
标签: swift animation swiftui ios-animations swiftui-environment