Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kylebshr/ScreenCorners
Check the display corner radius of an iOS device
https://github.com/kylebshr/ScreenCorners
Last synced: 3 months ago
JSON representation
Check the display corner radius of an iOS device
- Host: GitHub
- URL: https://github.com/kylebshr/ScreenCorners
- Owner: kylebshr
- License: mit
- Created: 2020-10-24T20:03:32.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T21:08:24.000Z (about 1 year ago)
- Last Synced: 2024-07-15T11:58:14.308Z (4 months ago)
- Language: Swift
- Homepage:
- Size: 22.5 KB
- Stars: 208
- Watchers: 6
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ScreenCorners
Check the corner radius of an iPhone / iPad display.
### Implementation
Adds a `displayCornerRadius` property to `UIScreen`, which reads the private `_displayCornerRadius`. The selector somewhat obscured, which usually means it will get past app review. However, use at your own risk!
#### Why didn't you hardcode the values instead?
I didn't want to use model identifiers (i.e., `iPhone10,2`) and miss an international variant, or have to update it when new devices launch.
It's also tricky to use screen resolutions, as multiple devices share the same resolution and scale with different corner radii. Display Zoom messes with this too, and ultimately it just seems like a bad idea to assume anything about the device based on the display resolution.
### How to use
iOS device displays use a continious corner curve, which means the corners are not true circles. In iOS 13+ you can use `CALayer.cornerCurve` to specify a continuous corner curve. You might create a view subclass like this:
```swift
class DisplayCornerMatchingView: UIView {
override func layoutSubviews()
super.layoutSubviews()
layer.cornerCurve = .continuous
layer.cornerRadius = window?.screen.displayCornerRadius ?? 0
}
}
```Or perhaps you want to animate from a different corner radius to the screen one. Either way, be sure to set `layer.cornerCurve = .continuous` on the view.
### Values reported
The following values were reported for various devices with rounded corners:
| Device | Value (pts) |
|--|--|
| iPhone X, Xs, Xs Max, 11 Pro, 11 Pro Max | 39.0 |
| iPhone Xr, 11 | 41.5 |
| iPhone 12 mini, 13 mini | 44.0 |
| iPhone 12, 12 Pro, 13 Pro, 14 | 47.33 |
| iPhone 12 Pro Max, 13 Pro Max, 14 Plus | 53.33 |
| iPhone 14 Pro, 14 Pro Max, 15, 15 Plus, 15 Pro, 15 Pro Max | 55.0 |
| iPad Air / iPad Pro 11-inch / 12.9-inch | 18.0 |