Latest 2.0.0
Homepage https://github.com/theoriginalbit/UIDeviceIcon
License MIT
Platforms ios 8.0
Dependencies UIDeviceModel
Authors

Language
License
Pod Version
Carthage Compatible

A µframework to detect and provide an icon to represent the device model through an extension of UIDevice. Also detects the simulator and the device model it is simulating.

Installation

CocoaPods

pod 'UIDeviceIcon', '~> 2.0'

Carthage

github "theoriginalbit/UIDeviceIcon"

Usage

First import the framework

import UIDeviceIcon

Common usage would be to use in a switch statement

let deviceIcon = UIDevice.current.deviceIcon

switch deviceIcon {
case .deviceIcon(let deviceIcon):
    break // You have a CADeviceLayer (CAShapeLayer), now do with it as you wish!
case .unknown(let deviceIdentifier):
    break // UIDeviceModel was unable to determine what device this identifier matched
case .unsupported(let deviceModel):
    break // UIDeviceIcon does not have an SVG path to represent this device model
}

As of version 1.2 you can specify colours of the screen and speaker, camera, and home button (when available).

let deviceIcon: CADeviceLayer = ...

deviceIcon.bezelColor = .white // .fillColor also works
deviceIcon.screenColor = .red
deviceIcon.cameraColor = .green
deviceIcon.speakerColor = .orange
deviceIcon.homeColor = .blue

Take a look at the Example application for a working implementation.

Latest podspec

{
    "name": "UIDeviceIcon",
    "version": "2.0.0",
    "summary": "A u00b5framework to provide an icon to represent the device model.",
    "description": "A u00b5framework to detect and provide an icon to represent the device model through an extension of UIDevice. Also detects the simulator and the device model it is simulating.",
    "homepage": "https://github.com/theoriginalbit/UIDeviceIcon",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "theoriginalbit": "[email protected]"
    },
    "source": {
        "git": "https://github.com/theoriginalbit/UIDeviceIcon.git",
        "tag": "2.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "UIDeviceIcon/Classes/**/*",
    "swift_version": "5.0",
    "dependencies": {
        "UIDeviceModel": [
            "~> 2.0"
        ]
    }
}

Pin It on Pinterest

Share This