ios - 使用全屏图像和导航查看链接

标签 ios swift swiftui

我是 swiftui 的新手,正在为一些基本的东西苦苦挣扎 我正在尝试创建一个在按钮上有 2 个按钮的 View 。 我想要一张图片作为整个 View 的背景。

var body: some View {
        ZStack {
            Image("bg-welcome").edgesIgnoringSafeArea(.all)
        }
    }

这很好用 我这样设置 View

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)
            }
        }
    }

关于ios - 使用全屏图像和导航查看链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787967/

相关文章:

ios - SWIFT - UIDatePicker - 开始和结束日期选择,但无法弄清楚如何将这两个日期调用到两个不同的文本框中

ios - CoreData Merge 变更异常

ios - 获取 swift 框架的 plist

ios - TableView 不显示单元格

ios - 实现介绍序列的最佳方式? swift

SwiftUI:为什么第二个警报没有显示?

ios - 在 UITextview 中显示响应时出错

ios - Alamofire 5 调整和重试请求

swift - 如何阻止 swiftui 在 HStack 中将内容移出屏幕?

ios - 从 UIViewController 导航到 SwiftUI View