ios - 使用全屏图像和导航查看链接
问题描述
我是 swiftui 的新手,并且正在为一些基本的东西而苦苦挣扎,我正在尝试在按钮上创建一个带有 2 个按钮的视图。我想要一个图像作为整个视图的背景。
var body: some View {
ZStack {
Image("bg-welcome").edgesIgnoringSafeArea(.all)
}
}
这很好用我这样设置我的视图
NavigationView {
ZStack {
VStack(alignment: HorizontalAlignment.leading, spacing: 10) {
Text("1").foregroundColor(.white)
Text("2").foregroundColor(.white)
Spacer()
Button(action: {}){
Text("ooooooooo")
}
}.background(Image("bg-welcome"))
}
}
现在我有两个问题: - 在背景图像之前显示一个空白 - 第一个文本被推到下面,肯定是在为导航栏保留的空间之后,我不想要它,因为当我导航到下一个屏幕时,空间仍然被占用,我想要整个可用的屏幕
谢谢您的帮助
解决方案
尝试这个:
var body: some View {
NavigationView {
ZStack {
VStack(alignment: HorizontalAlignment.leading, spacing: 10) {
Text("1").foregroundColor(.white)
Text("2").foregroundColor(.white)
Spacer()
Button(action: {}){
Text("Button 1")
}
Button(action: {}){
Text("Button 2")
}
}.background(Image("remachine_poster")
.resizable()
.aspectRatio(contentMode: .fill)).edgesIgnoringSafeArea(.all)
}
}
}
推荐阅读
- ruby - 将块作为参数传递和将 proc 作为参数传递有什么区别?
- javascript - 如何返回两个ajax响应
- r - 在闪亮仪表板中每行放置一个框
- python - 位置为 0 的 create_category_channel() 在底部创建通道
- javascript - 通过 JavaScript 打开 CHM 帮助文件到特定页面
- powershell - 在执行 AD 操作时嵌套 IF
- javascript - 使用 rxjs 以角度发送多个帖子请求
- excel - 减少 excel 中的嵌套 IF 和 sumif
- javascript - 在 Firefox 与 Chrome 上解析 JSON(错误:JSON.parse:JSON 数据的第 1 行第 1 列的数据意外结束)
- javascript - 如何更改反应选择标签边框半径