ScreenType 1.1.0

ScreenType 1.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2018 年 9 月
SPM支持 SPM

Max Stein 维护。




ScreenType

ScreenType

Version License Platform

在 Objective-C 和 Swift 中轻松区分 iPhone 模型。

示例

要演示示例项目,克隆或下载仓库,然后从 "Example" 目录打开 "ScreenType.xcworkspace"

要求

Swift 4.0+

Xcode 9.0+

iOS 9.0+

安装

ScreenType 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'ScreenType'

手动安装

手动通过导入 ScreenType.swift 到您的项目中安装 ScreenType

使用说明

Swift

如果您使用 Cocoapods,请在您的文件中使用 ScreenType 之前添加:import ScreenType

// Check for a specific model
if UIScreen.current == .iPhone5_8 {
    print("Screen type is iPhone X")
}

// Check for multiple models
if UIScreen.current == .iPhone4_7 || UIScreen.current == .iPhone5_5 {
    print("Screen type is either iPhone 6/7/8 or 6/7/8 Plus")
}

// Find all models smaller than a certain screen size
if UIScreen.current < .iPhone4_7 {
    print("Screen is smaller than an iPhone 6/7/8")
}

// Find all models larger than or equal to a certain screen size
if UIScreen.current >= .iPad10_5 {
    print("Screen type is either iPad 10.5 or iPad 12.9")
}

Objective-C

您需要在 Objective-C 中使用 ScreenType 时,创建一个 桥接头

如果您使用 Cocoapods,还需要在文件的顶部添加 @import ScreenType;

// Check for a specific model
if ([UIScreen current] == ScreenTypeIPhone5_8) {
    NSLog(@"Screen Type is iPhone X");
}

// Find all models larger than a certain screen size
if ([UIScreen current] > ScreenTypeIPhone4_0) {
    NSLog(@"Screen is larger than an iPhone 5/S/C");
}

贡献

欢迎您分支并提交 pull 请求

作者

Max Stein | maxste.in | Twitter

许可证

ScreenType 在 MIT 许可证下可用。请参阅 LICENSE 文件以获取更多信息。