如何使用 SwiftUI 检测当前设备? [英] How to detect current device using SwiftUI?

查看:25
本文介绍了如何使用 SwiftUI 检测当前设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定所使用的设备是 iPhone 还是 iPad.

I am trying to determine whether the device being used is iPhone or iPad.

请看这个问题:检测当前设备Swift 中的 UI_USER_INTERFACE_IDIOM()

如果您使用 UIKit,则该解决方案有效.但是

That solution works if you use UIKit. But

如果您使用的是 SwiftUI,那么等效的方法是什么?

What is the equivalent method if you are using SwiftUI ?

推荐答案

你可以找到设备类型,像这样:

you can find the device type, like this:

if UIDevice.current.userInterfaceIdiom == .pad {

    }

这篇关于如何使用 SwiftUI 检测当前设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆