UIDeviceIcon 2.0.0

UIDeviceIcon 2.0.0

Maintained by theoriginalbit.



  • By
  • theoriginalbit

UIDeviceIcon

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.