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
To find out the dimensions of a UIView
in an iOS app, use one of the following
properties:
NSMeasurement<NSUnitLength *> *width = view.irl_physicalWidth;
NSMeasurement<NSUnitLength *> *height = view.irl_physicalHeight;
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:
let width = view.physicalWidth // type: Measurement<UnitLength>
let height = view.physicalHeight // type: Measurement<UnitLength>
If you want to ensure that a view matches a certain physical size, IRLSize provides transforms to help you out:
NSMeasurement<NSUnitLength *> *desiredHeight =
[[NSMeasurement alloc] initWithDoubleValue:38.0
unit:NSUnitLength.millimeters];
view.transform = [view irl_transformForPhysicalHeight:desiredHeight];
let desiredHeight = Measurement(value: 38, unit: UnitLength.millimeters)
view.transform = view.transform(forPhysicalHeight: desiredHeight)
If you just want to know the physical size of the screen, use the category on
UIDevice
for iOS or WKInterfaceDevice
for watchOS:
// iOS
NSMeasurement<NSUnitLength *> *screenHeight = UIDevice.currentDevice.irl_physicalScreenHeight;
// watchOS
NSMeasurement<NSUnitLength *> *screenHeight = WKInterfaceDevice.currentDevice.irl_physicalScreenHeight;
// iOS
let screenHeight = UIDevice.current.physicalScreenHeight
// watchOS
let screenHeight = WKInterfaceDevice.current.phsyicalScreenHeight
IRLSize is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "IRLSize"
Jeff Kelley (SlaunchaMan@gmail.com) at Detroit Labs.
IRLSize is available under the MIT license. See the LICENSE file for more info.