Search code examples
iosuikitmodalviewcontroller

Is there a standard way to display a modal view indicator?


Most of the Apple iOS app have a small indicator at the top of their modal content:

enter image description here

I tried looking for it but I can't even figure out what to call that item.


Solution

  • Here is a Modal View Indicator

    import SwiftUI
    
    struct ModalViewIndicator: View {
        var body: some View {
            HStack {
                Spacer()
                Image(systemName: "minus")
                    .imageScale(.large)
                    .font(Font.title.weight(.heavy))
                    .foregroundColor(Color(UIColor.tertiaryLabel))
                Spacer()
            }.padding(4)
        }
    }
    
    struct ModalViewIndicator_Previews: PreviewProvider {
        static var previews: some View {
            Text("ModalViewIndicator")
                .sheet(isPresented: .constant(true)) {
                    VStack {
                        ModalViewIndicator()
                        GeometryReader { geometry in
                            Image(systemName: "sun.dust.fill")
                                .resizable()
                                .frame(
                                    width: geometry.size.width/2,
                                    height: geometry.size.width/2,
                                    alignment: .center
                            )
                        }
                    }
            }
        }
    }
    

    enter image description here