在归档/构建使用 SwiftUI 平台 <= iOS 10 的应用程序时,编译器会抛出错误“使用未声明的类型”。
即使封闭类型被标记为 @available(iOS 13.0, *) 并且还使用 #if canImport(SwiftUI),也会发生这种情况。
SwiftUI 框架也是弱链接。
如果您在 iOS 11+ 设备上运行(调试),或者为最低支持版本 <= iOS 11 的目标存档,则一切正常。
在 SwiftUI Shapes 中,我们可以使用渐变来制作不同的颜色描边。
例如-
@ViewBuilder
func lineWithSecondColorStyleFromPositionN() -> some View {
let n = 0.5
GeometryReader { gr in
Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: gr.size.width, y: gr.size.height))
}
.stroke(
LinearGradient(stops: [
Gradient.Stop(color: .red, location: 0),
Gradient.Stop(color: .red, location: n),
Gradient.Stop(color: .blue, location: n),
Gradient.Stop(color: .blue, location: 1)
], startPoint: .top, endPoint: .bottom),
style: StrokeStyle(lineWidth: 10, lineCap: .butt)
)
}
.frame(height: 200)
}
Run Code Online (Sandbox Code Playgroud)
是否可以通过任何方式对笔划样式执行相同的操作?
创建这样的东西 -
笔划样式 1(实线)从 0 到n,
描边样式 2(虚线)从 …
有没有办法用 SwiftUI 创建这样的东西(不使用 D3.js) -
// test data
@State private var data: [DataItem] = [
DataItem(title: "chrome", weight: 180, color: .green),
DataItem(title: "firefox", weight: 60, color: .red),
DataItem(title: "safari", weight: 90, color: .blue),
DataItem(title: "edge", weight: 30, color: .orange),
DataItem(title: "ie", weight: 50, color: .yellow),
DataItem(title: "opera", weight: 25, color: .purple)
]
Run Code Online (Sandbox Code Playgroud)
在测试数据中,“权重”表示哪个项目应该更大/更小。
我能想到的一种方法是在给定视图中设置 X 个圆圈,其大小相对于父级。但这本身就造成了定位和确保圆圈不会相互接触或重叠的问题。
不确定这里SpriteKit的用法?可以使用它还是可以仅使用 SwiftUI 组件来实现?