struct ContentView: View {
var body: some View {
VStack(alignment: .menu) {
HStack {
Text("Inbox")
CircleButton()
.frame(width: 30, height: 30)
.alignmentGuide(.menu) { $0.width / 2 }
}
HStack {
Text("Sent")
CircleButton()
.frame(width: 30, height: 30)
.alignmentGuide(.menu) { $0.width / 2 }
}
CircleButton()
.frame(width: 40, height: 40)
}
}
@ViewBuilder
func CircleButton() -> some View {
Circle()
.fill(.gray)
}
}
struct MenuAlignment: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat {
context.width / 2
}
}
extension HorizontalAlignment {
static let menu = HorizontalAlignment(MenuAlignment.self)
}
效果图:
Loading Comments...