All Projects → detroit-labs → IRLSize

detroit-labs / IRLSize

Licence: MIT License
A library for determining the actual physical size of pixels on an iOS device.

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language
swift
15916 projects
c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to IRLSize

device-mockups
No longer mirroring this repo with .org
Stars: ✭ 27 (+92.86%)
Mutual labels:  devices
gems
Ruby Football Week 2021, June 11th to June 17th - 7 Days of Ruby (Sports) Gems ++ Best of Ruby Gems Series
Stars: ✭ 76 (+442.86%)
Mutual labels:  pixels
unit-converter
Convert standard units from one to another with this easy to use, lightweight package
Stars: ✭ 104 (+642.86%)
Mutual labels:  measurements
cutie-shell
A mobile QtWayland compositor and shell and for smartphones and tablets.
Stars: ✭ 21 (+50%)
Mutual labels:  devices
insomnia
😪 NativeScript plugin to keep the device awake (not dim the screen, lock, etc)
Stars: ✭ 40 (+185.71%)
Mutual labels:  screen
n2t-wasm
Emulator for the Hack CPU.
Stars: ✭ 41 (+192.86%)
Mutual labels:  pixels
flutter scale aware
🎗 Scale-based layouts with a bit more ease, powered by extensions.
Stars: ✭ 26 (+85.71%)
Mutual labels:  screen
FloBaRoID
Framework for dynamical system identification of floating-base rigid body tree structures
Stars: ✭ 53 (+278.57%)
Mutual labels:  measurements
pixel-bird-jump
🐦 A small flappy-bird-like game demo by Godot engine
Stars: ✭ 13 (-7.14%)
Mutual labels:  pixels
ScreenRuler
Configurable screen measuring tool for Windows
Stars: ✭ 147 (+950%)
Mutual labels:  pixels
PPG
Code to estimate HR from PPG signals using Subspace Decomposition and Kalman filter for the dataset of 22 PPG recordings provided for the 2015 IEEE Signal Processing Cup (SP Cup) competition. The traces are stored in folder 'DATABASE'. Please cite this publication when referencing this material: "Measuring Heart Rate During Physical Exercise by …
Stars: ✭ 43 (+207.14%)
Mutual labels:  measurements
screencast
Interface to record a X11 desktop
Stars: ✭ 91 (+550%)
Mutual labels:  screen
Mosque-Screen
Chat: https://discord.gg/CG7frj2 - Email: [email protected]. We do not provide any support, this is a volunteer-based project therefore we cannot commit to any time to resolve local issues.
Stars: ✭ 54 (+285.71%)
Mutual labels:  screen
clothing-sizing
simple computer vision learning project to get the estimated dimensions of jeans, trousers and pants
Stars: ✭ 15 (+7.14%)
Mutual labels:  measurements
iosdevices
iOS device model translation from Apple device types.
Stars: ✭ 14 (+0%)
Mutual labels:  devices
tmux-slay
TMUX script to run commands in a background session. Similar to abduco/dtach.
Stars: ✭ 18 (+28.57%)
Mutual labels:  screen
semetrics
Speech Enhancement Metrics (PESQ, CSIG, CBAK, COVL)
Stars: ✭ 39 (+178.57%)
Mutual labels:  measurements
pi pico neopixel
Pi Pico library for NeoPixel led-strip written in MicroPython. Works with ws2812b (RGB) and sk6812 (RGBW).
Stars: ✭ 70 (+400%)
Mutual labels:  pixels
sr graph
A simple, one-file, header-only, C++ utility for graphs, curves and histograms.
Stars: ✭ 67 (+378.57%)
Mutual labels:  points
RulerView
simple ruler library for android, with Calibration and Dimension measurement 📏 .
Stars: ✭ 21 (+50%)
Mutual labels:  measurements

IRLSize

Version License Platform

Getting Started

To run the example project, clone the repo and navigate to its root folder in Terminal. Run the following command to install dependencies in their proper location:

pod install --project-directory=Example

Use

All IRLSize methods have two versions: one that uses NSMeasurement (Measurement in Swift), and one that uses the IRLRawMillimeters type (a double measuring millimeters).

Important: Upgrading to IRLSize 2.0

IRLSize 2.0 switched the native unit for measurements from meters to millimeters to better manage what official Apple documentation there is on device sizes. This is a breaking change and as such the raw unit type changed from IRLRawLengthMeasurement to IRLRawMillimeters to avoid this change accidentally changing existing code by a factor of 1,000. If you were using NSMeasurement, no updates should be necessary, as it automatically converts between units.

Measuring an On-Screen Element

To find out the dimensions of a UIView in an iOS app, use one of the following properties:

Objective-C

// NSMeasurement Version
NSMeasurement<NSUnitLength *> *width = view.irl_physicalWidth;
NSMeasurement<NSUnitLength *> *height = view.irl_physicalHeight;

// Raw Version
//   `IRLRawMillimeters` is a `double` representing millimeters. 
IRLRawMillimeters rawWidth = view.irl_rawPhysicalWidth;
IRLRawMillimeters rawHeight = view.irl_rawPhysicalHeight;

If a view is on a secondary screen (i.e. if you’re using an external display) the measurements will be returned as nil.

Of course, this also works nicely in Swift:

Swift

// Measurement Version
let width = view.physicalWidth // type: Measurement<UnitLength>
let height = view.physicalHeight // type: Measurement<UnitLength>

// Raw Version
let rawWidth = view.rawPhysicalWidth // type: IRLRawMillimeters
let rawHeight = view.rawPhysicalHeight // type: IRLRawMillimeters

Sizing a View

If you want to ensure that a view matches a certain physical size, IRLSize provides transforms to help you out:

Objective-C

// NSMeasurement Version
NSMeasurement<NSUnitLength *> *desiredHeight =
[[NSMeasurement alloc] initWithDoubleValue:38.0
                                      unit:NSUnitLength.millimeters];

view.transform = [view irl_transformForPhysicalHeight:desiredHeight];

// Raw Version
view.transform = [view irl_transformForRawPhysicalHeight:38.0];

Swift

// Measurement Version
let desiredHeight = Measurement(value: 38, unit: UnitLength.millimeters)

view.transform = view.transform(forPhysicalHeight:desiredHeight)

// Raw Version
view.transform = view.transform(forRawPhysicalHeight:38);

Measuring a Device

If you just want to know the physical size of the screen, use the category on UIDevice for iOS or WKInterfaceDevice for watchOS:

Objective-C

// iOS
NSMeasurement<NSUnitLength *> *screenHeight = UIDevice.currentDevice.irl_physicalScreenHeight;
IRLRawMillimeters rawScreenHeight = UIDevice.currentDevice.irl_rawPhysicalScreenHeight;

// watchOS
NSMeasurement<NSUnitLength *> *screenHeight = WKInterfaceDevice.currentDevice.irl_physicalScreenHeight;
IRLRawMillimeters rawScreenHeight = WKInterfaceDevice.currentDevice.irl_rawPhysicalScreenHeight;

Swift

// iOS
let screenHeight = UIDevice.current.physicalScreenHeight
let rawScreenHeight = UIDevice.current.rawPhysicalScreenHeight

// watchOS
let screenHeight = WKInterfaceDevice.current.phsyicalScreenHeight
let rawScreenHeight = WKInterfaceDevice.current.rawPhysicalScreenHeight

Installation

IRLSize is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "IRLSize"

Author

Jeff Kelley ([email protected]) at Detroit Labs.

License

IRLSize is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].