【问题标题】:How to fill gray space with black ? SwiftUI如何用黑色填充灰色空间? SwiftUI
【发布时间】:2021-10-28 14:08:42
【问题描述】:

如何用黑色绘制一个完全灰色的空间?看图片 这是我的代码:

.onTapGesture {
            self.showModal = true
        }.sheet(isPresented: self.$showModal, onDismiss: {
//            addEntry()
//            requestReviewIfNeeded()
            self.showModal = false
        }, content: {
            
            BiographyDetail(biography: self.biography)
                
            
            Button(action: {
                showModal = false
            }) {
                Text("CLOSE")
                    .foregroundColor(.gray)
                    .background(Color.black).ignoresSafeArea()
            }
  
        })

感谢您的帮助!

【问题讨论】:

    标签: ios swift xcode swiftui


    【解决方案1】:

    这是一种可能的方法 - 使用颜色作为背景并将特定内容放置在此颜色的叠加层中。

    使用 Xcode 13 / iOS 15 测试

    .sheet(isPresented: $showModal) {
        Color.black
            .ignoresSafeArea()   // << consumes all space
            .overlay(            // << content is overlaid 
                VStack(spacing: 0) {
                    BiographyDetail(biography: self.biography)
    
    
                    Button(action: {
                        showModal = false
                    }) {
                        Text("CLOSE")
                            .foregroundColor(.gray)
                            .background(Color.black).ignoresSafeArea()
                    }
                })
    }
    

    【讨论】:

    • 非常感谢!它有效)
    【解决方案2】:

    将框架添加到Text

    Text("CLOSE")
        .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
        .foregroundColor(.gray)
        .background(Color.black).ignoresSafeArea()
    
    

    【讨论】:

    • 它对我不起作用(按钮占据了屏幕的一半并与我的内容重叠i.ibb.co/Qjp80tM/IMG-8064.jpg
    • 使用 VStack 以及 VStack 中的第一个容器和按钮。
    • 它也没有帮助我
    • 可以显示 BiographyDetail 视图代码吗?
    • 您可以尝试将 .fixedSize(horizo​​ntal: false, vertical: true) 添加到您的详细信息视图中。
    【解决方案3】:

    Text("CLOSE") .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .foregroundColor(.gray) .background(Color.black).ignoresSafeArea()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      相关资源
      最近更新 更多