我正在尝试编写一个PickerStyle看起来类似于SegmentedPickerStyle(). 这是我目前的状态:
import SwiftUI
public struct FilterPickerStyle: PickerStyle {
public static func _makeView<SelectionValue>(value: _GraphValue<_PickerValue<FilterPickerStyle, SelectionValue>>, inputs: _ViewInputs) -> _ViewOutputs where SelectionValue : Hashable {
}
public static func _makeViewList<SelectionValue>(value: _GraphValue<_PickerValue<FilterPickerStyle, SelectionValue>>, inputs: _ViewListInputs) -> _ViewListOutputs where SelectionValue : Hashable {
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个符合 PickerStyle 协议的结构。Xcode然后添加了所需的协议方法,但我不知道如何使用它们。有人可以解释如何处理这些方法,例如,如果我想实现类似于SegmentedPickerStyle()?
在阅读问题之前,请先看一下这张图片

我目前正在尝试将红色视图的垂直中心 (/centerY) 与 SwiftUI 视图中绿色视图的底部边缘对齐。
我来自 UIKit,在那里我会用类似的方法解决这个问题 viewA.centerYAnchor.constraint(toEqual: viewB.bottomAnchor)
但是您将如何以 SwiftUI 的方式解决这个问题?我有以下层次结构:
VStack {
ZStack {
Image("someImage")
Text("Awesome Title") // <- align center to the Image's bottom edge
.frame(width: 200, height: 130)
}
Spacer()
}
Run Code Online (Sandbox Code Playgroud)