【问题标题】:SwiftUI: Can I remove the white background behind this button?SwiftUI:我可以删除这个按钮后面的白色背景吗?
【发布时间】:2021-02-11 01:09:38
【问题描述】:

*我创建了这个视图,当在我的应用程序的主视图中点击一个按钮时,它显示为一个工作表。我想知道是否有办法删除底部搜索按钮后面的白色背景?抱歉,如果这些信息不够多,请告诉我,我会添加更多信息

import SwiftUI
struct AddDoujin: View {
//variables
    
    var body: some View {
        GeometryReader{ geo in
            ZStack {
                VStack{
                    HStack{
                        Form {
                            Text("Enter The Sauce:")
                                TextField("Enter the Sauce Degen", text:$InputDoujin, onCommit: {
                                    UIApplication.shared.keyWindow?.endEditing(true)
                                })
                                .keyboardType(.numberPad)
                            //Code
                    }
                    //The button checks if it needs to be redone or not
                    //If it doesnt it closes the sheet while also calling the api
                    ZStack{
                        Button(action: {
                             //Action
                            }
                            
                        }){
                            ZStack {
                                Circle()
                                    .foregroundColor(Color("DarkPurple"))
                                    .frame(width: 80, height: 80)
                                
                                Text("Search")
                            }
                            
                        }
                    }
                }
                
                
                .buttonStyle(PlainButtonStyle())
            }
        }
        
    }
}
struct AddDoujin_Previews: PreviewProvider {
    static var previews: some View {
        AddDoujin(DoujinApi: DoujinAPI(), isPresented: .constant(false))
    }
}

【问题讨论】:

  • 用完这个应用程序后告诉我? ????
  • @aheze 我的意思是如果你查看我的 GitHub,我已经有类似的东西了。不过,目前的这个会好 10 倍。
  • 哦,太好了!完美的!我去看看。
  • @aheze 你能给我发消息吗?我有一个问题
  • 当然,我的不和谐是 aheze#3125

标签: swift swiftui


【解决方案1】:

一种解决方案是使用您已经在使用的ZStack,然后使用对齐方式或VStackSpacer 将按钮向下推——我已经完成了后者。

这样,您可以保留表格视图的背景颜色,但仍然可以将按钮放置在您想要的位置。请注意,这个 确实 具有现在浮动在表单视图上方的按钮的副作用。因此,如果您的表单明显变长,它可能并不理想,因为按钮可能会覆盖表单元素。但是,对于您的示例,它运行良好:

struct AddDoujin: View {
    //variables
    
    var body: some View {
        ZStack {
            Form {
                Text("Enter The Sauce:")
                TextField("Enter the Sauce Degen", text:.constant("test"), onCommit: {
                    UIApplication.shared.keyWindow?.endEditing(true)
                })
                .keyboardType(.numberPad)
            }
            
            VStack {
                Spacer()
                Button(action: {
                    //Action
                }) {
                    ZStack {
                        Circle()
                            .foregroundColor(Color.red)
                            .frame(width: 80, height: 80)
                        
                        Text("Search")
                    }
                    
                }.buttonStyle(PlainButtonStyle())
            }
        }
        
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2023-02-20
    • 1970-01-01
    相关资源
    最近更新 更多