swift - SwiftUI create custom menu with frame and items
问题描述
I have a problem. I have a main view to build but I cannot manage how to do it like it is on screen. I tried to use 3 HStack's in VStack, but cannt manage what to do next, use frame or overlay, completelly newbie in SwiftUI. Menu items will contains images and text below. Does anyone can help me with that. Greetings enter image description here
解决方案
Here is a possible solution. Using VStack as main wrapper then HStack as rows where every Item tries to have to maximum width.
struct ContentView: View {
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 0) {
ItemView()
ItemView()
}
HStack(spacing: 0) {
ItemView()
ItemView()
}
HStack(spacing: 0) {
ItemView()
ItemView()
}
}
}
}
struct ItemView : View {
var body : some View {
VStack {
Spacer()
Image(systemName: "airplane")
.resizable()
.frame(width: 50, height: 50)
Spacer()
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.border(Color.black)
}
}
推荐阅读
- node.js - 如何在 node.js 中全局使用 socket.io
- python - 熊猫数据框中看不到一些空行
- java - ThreadPoolExecutor : 拉出挂起的任务
- python - 如何使用python对csv文件中的多个单元格进行合并操作?
- java - 整数比整数慢吗?
- bash - bash 脚本在获取时会产生不同的结果
- ios - 如何从子类化 UIButton 切换隐藏 imageView
- r - 根据数据框R中另一列中的值复制值
- javascript - 为什么 texfield 的参与会以这种方式 textfield.value 起作用,而另一次我必须使用 $("#textfield").val()
- angular - 在本地使用 pdftron webviewer 服务器时无法加载 pdf 文件