GithubHelp home page GithubHelp logo

maksimkurpa / uiscreenextension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marchv/uiscreenextension

0.0 2.0 0.0 11 KB

An extension to UIScreen that offers information about the pixel density (or point density) of iPhones and iPads.

License: MIT License

Ruby 14.50% Objective-C 8.30% Swift 77.20%

uiscreenextension's Introduction

UIScreenExtension

This is an extension to UIScreen that provides information about the pixel density (or point density) of iPhones and iPads. For example this can be used to:

  • compute the dimension of the screen

  • draw a ruler; or

  • to show a proper ECG graph on the iPhone's screen.

    public extension UIScreen {
    
      /// The number of pixels per inch for this device
      public static let pixelsPerInch: CGFloat?
      
      /// The number of pixels per centimeter for this device
      public static let pixelsPerCentimeter: CGFloat?
      
      /// The number of points per inch for this device
      public static let pointsPerInch: CGFloat?
      
      /// The number of points per centimeter for this device
      public static let pointsPerCentimeter: CGFloat?
      
      /// The screen dimension in inches
      public static let dimensionInInches: CGSize?
      
      /// The screen dimension in centimeters
      public static let dimensionInCentimeters: CGSize?
    }
    

The constants will be set to .none if the device is unknown. This can happen if Apple releases a new iPhone, so please remember to deal with this in your code.

Installation and use

The extension can be installed using Cocoapods by adding below line to your Podfile:

pod 'UIScreenExtension', :git => 'https://github.com/marchv/UIScreenExtension'

To use the extension in your code first import it by adding:

import UIScreenExtension

And then use it for example:

if let pointsPerCentimeter = UIScreen.pointsPerCentimeter {
   // code
}

Or to compute the diagonal screen dimension:

if let dimensionInInches = UIScreen.dimensionInInches {
    print(sqrt(pow(dimensionInInches.width, 2) + pow(dimensionInInches.height, 2))) // for example ~5.5 inches for iPhone 7 Plus
}

Support

The extension supports all iPhones, iPods and iPads that are supported by iOS 9-11.

Limitations

Please note that iPhone only apps upscaled on iPads will not work properly!

Improvements

  • Apple Watch support
  • Objective C support
  • Fetch information about new iPhone models from internet

Author

[email protected]

:)

uiscreenextension's People

Contributors

marchv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.