SwiftUI: Sizing a popover to fit

前端 未结 2 1397
暖寄归人
暖寄归人 2020-12-15 00:21

I\'ve got a little popover sample in which a button triggers a popover. The popover only contains a little bit of UI, two buttons in this case, but it still takes up a lot o

相关标签:
2条回答
  • 2020-12-15 00:59

    It looks like this has been fixed in iOS 13.4 / Xcode 11.4 Beta. The popover will size to whatever it's contents are now.

    0 讨论(0)
  • 2020-12-15 01:20

    On macOS the code below will look like this:

    struct PopoverExample: View {
    
        @State private var showingPopupA:Bool = false 
        var body: some View {
            HStack {
                Button(action: {
                    self.showingPopupA.toggle()
                }, label: {
                    Text("Button")
                }).popover(isPresented: self.$showingPopupA) {
                    VStack {
                        Button(action: {
                            // Do something
                            self.showingPopupA = false
                        }) {
                            Text("Option A")
                        }
                        Button(action: {
                            // Do something
                            self.showingPopupA = false
                        }) {
                            Text("Option B")
                        }
                    }.background(Color.red)
                }
            }
            .frame( maxWidth: .infinity, maxHeight: .infinity)
        }
    }
    

    Project link

    0 讨论(0)
提交回复
热议问题