Git Product home page Git Product logo

screencorners's Introduction

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:

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

On iOS 14.1, the follow values were reported for each device 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 44.0
iPhone 12 / 12 Pro 47.33
iPhone 12 Pro Max 53.33
iPad Air / iPad Pro 11-inch / 12.9-inch 18.0

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.