swift - SwiftUI 设置图像边界
解决方案
您应该使用内置的TabView
. 它为您提供了所有功能,并且已经考虑到了可访问性。
这是一个示例(您可以为文本和图像更改它):
struct ContentView: View {
@State private var selection: Int = 1
var body: some View {
TabView(selection: $selection) {
Text("Tab Content 1")
.tabItem {
Label("1", systemImage: "1.square")
}
.tag(1)
Text("Tab Content 2")
.tabItem {
Label("2", systemImage: "2.square")
}
.tag(2)
Text("Tab Content 3")
.tabItem {
Label("3", systemImage: "3.square")
}
.tag(3)
}
}
}
结果:
自定义版本(非常不推荐):
struct ContentView: View {
var body: some View {
VStack {
Spacer()
Text("Main Content")
Spacer()
HStack {
VStack {
Button {
//
} label: {
Label("1", systemImage: "1.square")
}
}.frame(maxWidth: .infinity)
VStack {
Button {
//
} label: {
Label("2", systemImage: "2.square")
}
}.frame(maxWidth: .infinity)
VStack {
Button {
//
} label: {
Label("3", systemImage: "3.square")
}
}.frame(maxWidth: .infinity)
}.frame(height: 50)
}
}
}
推荐阅读
- machine-learning - 计算成本低廉的图像分类器
- javascript - 如何打印多个订单的运输标签
- google-cloud-platform - 如何处理 Google Cloud Run 中的长请求?
- javascript - 无法在纸质列表框聚合物 3 中获取多选值
- reactjs - 如何使用我的 react 组件 PlaceInput 实现菜单输入框中的位置自动补全?
- c - 在链表的链表中插入元素
- java - 我如何与其他人分享 klov 报告?
- arrays - 比较 beanshell 中的 3 个数组并得到 1 个数组
- database-design - “仅当分区键受 EQ 或 IN 限制时,才支持 ORDER BY。” 卡桑德拉
- python-2.7 - 带有 unicode 路径的 Python 2.7 子进程