0

How to change the size of modal or sheet in SwiftUI? Just like the ones in the pictures. I noticed that the AirDrop options appear as a full-screen sheet on iPhones but on iPads that is not the case (as you can see).

I'm creating an app with a login form, this size personalization would be useful to optimize the size of the device because most of the space isn't used.

Is there a way to change the size of those components?

enter image description here

bravemoon
  • 47
  • 7
  • Please add a minimal example which demonstrates how you show an alert and a sheet in some demo "ContentView". Ensure you only include the relevant UI as examples and nothing from your login. – CouchDeveloper Aug 06 '21 at 11:04
  • When it comes to "built-in" there is only half and full as if iOS15. You also need to tap into UIKit for it. Any other size and you have to create it on your own. https://stackoverflow.com/questions/56700752/swiftui-half-modal/67994666#67994666 – lorem ipsum Aug 06 '21 at 13:00
  • you might wanna take a look here : https://stackoverflow.com/a/73251032/6347902 – Bessem ben afia Aug 05 '22 at 14:12

1 Answers1

1

From your description, I didn't really understand what do you want to achieve, but this enum will help you to determine what device is currently running. You can build a logic of what do you want to present around a simple if else statement:

if DeviceTypes.isiPad {
// logic for all iPads
} else {
// logic for other devices
}

And here is Enum:

enum DeviceTypes {
    enum ScreenSize {
        static let width     = UIScreen.main.bounds.size.width
        static let height    = UIScreen.main.bounds.size.height
        static let maxLength = max(ScreenSize.width, ScreenSize.height)
    }
    
    static let idiom         = UIDevice.current.userInterfaceIdiom

    static let isiPad        = idiom == .pad && ScreenSize.maxLength >= 1024.0
}
Roma Kavinskyi
  • 268
  • 4
  • 12