How to get the screen width and height in iOS?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
On iOS, getting screen width and height is easy, but choosing the correct measurement depends on what you actually need. UIScreen.main.bounds gives you the full screen size in points, while many layout tasks are better served by a view’s bounds or safe area instead of the raw physical screen dimensions.
Get the Full Screen Size in Points
If you want the dimensions of the main display, use UIScreen.main.bounds.
These values are in points, not pixels. That is the coordinate system UIKit layout works with by default.
Understand Points Versus Pixels
Developers often expect physical pixels, but iOS layout uses logical points. If you need pixel dimensions, multiply by the screen scale.
Use this only when pixel counts are truly required, such as image processing or low-level rendering decisions.
Use View Bounds for Actual UI Layout
A common mistake is using full screen dimensions to size a view that lives inside a navigation controller, split view, sheet, or other container. In those cases, the relevant size is usually the current view’s bounds.
For layout work, view.bounds is often more correct than UIScreen.main.bounds because it reflects the space your controller actually owns.
Account for Safe Area Insets
Modern devices have notches, home indicators, and other edge constraints. If content must fit within the visible safe region, inspect the safe area instead of only the raw screen rectangle.
That gives the usable content region after system insets are applied.
Orientation and Window Size Can Change
Screen-related values are not always static in the way older tutorials suggest. Rotation, split view, Stage Manager, and modal presentations can all change the usable size of your interface.
That is why layout code should usually live in lifecycle points such as viewDidLayoutSubviews, Auto Layout constraints, or size-class driven updates, not in one early startup calculation.
If you are building adaptive UI, ask for the size when you need it rather than assuming the first value will remain correct forever.
Prefer Layout Systems Over Manual Screen Math
In many cases, directly reading width and height is not the best design. Auto Layout, stack views, and size classes can express intent more clearly and adapt automatically across devices.
Reading screen dimensions is fine for diagnostics, proportional calculations, or custom drawing. It becomes risky when it turns into hardcoded layout logic that ignores container behavior.
Common Pitfalls
- Using
UIScreen.main.boundsfor layout when the real requirement is the current view size. - Confusing points with pixels and applying the wrong unit in rendering code.
- Ignoring safe area insets on modern device layouts.
- Assuming screen-related measurements never change after initial load.
- Replacing Auto Layout with manual screen math where the framework already solves the problem better.
Summary
- Use
UIScreen.main.boundsto get full display size in points. - Multiply by
UIScreen.main.scaleonly when pixel dimensions are actually needed. - Use
view.boundsfor most real interface layout decisions. - Check the safe area when visible content space matters.
- Prefer adaptive layout systems over hardcoded screen-size calculations.

