SwiftUI获取设备信息

PHOTO EMBED

Sun Feb 12 2023 08:32:54 GMT+0000 (Coordinated Universal Time)

Saved by @zelda #swift #swiftui

//
//  DeviceInfoView.swift
//  SwiftUIDemo
//
//  Created by shiyanjun on 2023/2/12.
//

import SwiftUI

struct DeviceInfoView: View {
    let screenSize: CGSize = UIScreen.main.bounds.size
    let device: UIDevice = UIDevice.current
    
    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            Text("屏幕宽度:\(screenSize.width)")    // 屏幕宽度:430.000000
            Text("屏幕高度:\(screenSize.height)")   // 屏幕高度:932.000000
            Text("设备名称:\(device.name)")         // 设备名称:iPhone 14 Pro Max
            Text("系统名称:\(device.systemName)")   // 系统名称:iOS
            Text("系统版本:\(device.systemVersion)")// 系统版本:16.2
            Text("设备型号:\(device.model)")        // 设备型号:iPhone
        }
        .padding()
        .background(.orange)
        .cornerRadius(10)
    }
}

struct DeviceInfoView_Previews: PreviewProvider {
    static var previews: some View {
        DeviceInfoView()
    }
}
content_copyCOPY