Change UIPopoverView background + arrow color

后端 未结 5 1450
猫巷女王i
猫巷女王i 2021-01-03 18:19

Is there a way to simply change the UIPopoverView background color (including its arrow) on iOS8?

(I did read a couple of articles on customizing \"UIPopove

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 18:48

    Just adding that if you are using SwiftUI inside of a UIPopover or if you are using SwiftUI's popover modifier you can set the background color of the popover by just using a Color in the background, like as in a ZStack.

    If you want the arrow colored you can add the .edgesIgnoringSafeArea(.all) modifier to the color in the background so it will extend into the arrow.

    SwiftUI example:

    import SwiftUI
    
    struct PopoverTest: View {
        @State var showing: Bool = true
        var body: some View {
            Button("Show") {
                self.showing.toggle()
            }
            .popover(isPresented: $showing) {
                ZStack {
                    Color.green.edgesIgnoringSafeArea(.all) // will color background and arrow
                    Text("Popover!")
                }
            }
        }
    }
    
    struct PopoverTest_Previews: PreviewProvider {
        static var previews: some View {
            PopoverTest()
        }
    }
    

提交回复
热议问题