我正在尝试创建一个可调整大小的按钮,其周围有均匀的点状圆形边框。如果你简单地说:
Circle()
.stroke(color, style: StrokeStyle(lineWidth: 3, lineCap: .butt, dash: [3, radius / 3.82]))
.frame(width: radius * 2, height: radius * 2)
Run Code Online (Sandbox Code Playgroud)
这是一个相关的问题和一个解决方案,我尝试将 UIKit 调整为 SwiftUI 结构,但也失败了。
有人可以帮助我找到一种方法来适应“破折号”值以创建依赖于半径的均匀虚线描边边框或创建自定义形状吗?
Xcode11 beta5中swiftUI的Path.fill和.stroke不起作用
下面的代码在Xcode beta4中工作正常,但在Xcode beta5中崩溃,我得到的所有错误信息都是:线程1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)
代码:
import SwiftUI
struct ContentView: View {
var body: some View {
Path{path in
path.addRect(CGRect(x: 20, y: 20, width: 300, height: 200))
}.fill(Color.red)
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Run Code Online (Sandbox Code Playgroud)